How to pass user input from one js file to another

Sheriff

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)?

Funk Soul Ninja

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass data from one js file to another js file through app.js in reactjs

Pass an HTML file object from one <input type = file> to another

how do I call or pass the value from one js file to another file in react js

Java - Pass a variable from user input to another java file

Echo user input from one .php file to echo on another

SBT How to pass input from one inputTask to another inputTask

How to pass the data input from one component into another component?

React - How can I pass API data from one component to another in a different js file?

How can I pass form data from one html file to another without JS/PHP?

How to pass variables from one batch file to another batch file?

How to pass the results of a function from one file to another file

How to pass request object in laravel from one file to another file?

Pass user input (from TextField) to another class?

How to pass value from one cs-file (void!) to another?

How to pass variable from one Javascript to another Javascript file

How to pass object from one file to another in javascript?

How to pass data from one component to another in ts file?

How to pass term meta from one file to another

how to pass js value from one html page to another

How to pass the output of one echo to the input of another?

How to use a variable from one js file in another file?

pass value from one js file to another js file in react native :react native

Js how call function and pass params from another file

Pass variable from one php file to another

Pass a variable from one python file to another

Pass variables from one file to another in PHP

Pass a Variable from one file to another in WordPress

How to pass the user input in batch file?

How to call function from one js file to another