During the installation of my app (UI created with React), the user has the option to specify some specifications in a text field (How much memory to allocate to the vm, etc.). It is an optional part of installation and can be skipped (default values will be used) like so:
<div>
Memory size (MB): <TextField type="text" placeholder="4096" name="memory"/>
</div>
This information needs to be used as a parameter for a function in a different file:
export function createMachine(callback, size = 22000, mem = 6000) { }
So my question is how do I take the user input If the user provides it and use it as an argument in my createMachine
function (the size and mem arguments) and leave the default arguments if they choose not to (if the user doesn't want to specify, they will not be taken to the page with the text field)?
This looks like case for state, whether it's component level or app level with redux.
With component level state, you can use it with a function or method like so:
class MyComponent extends React.Component {
state = { myInput: '' };
myMethod = () => {
createMachine(this.state.myInput);
};
render() {
return (
<div>
Memory size (MB):
<TextField
type="text"
placeholder="4096"
value={this.state.myInput} // This makes it a controlled input
name="memory"
onChangeText={(text) => this.setState(state => ({ ...state, myInput: text }))}
/>
</div>
)
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments