Answers for "react how to pass the input target value"

3

react how to pass the input target value

class NameForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: ''};

    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(event) {
    this.setState({value: event.target.value});
  }

  render() {
    return (
      <form>
        <label>
          Name:
          <input type="text" value={this.state.value} onChange={this.handleChange} />
        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}
Posted by: Guest on March-18-2020

Code answers related to "react how to pass the input target value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language