Skip to content

Instantly share code, notes, and snippets.

@eduard-tkv
Created March 17, 2017 13:43
Show Gist options
  • Save eduard-tkv/a61691db0be9f4a07aa287d0084f1d34 to your computer and use it in GitHub Desktop.
Save eduard-tkv/a61691db0be9f4a07aa287d0084f1d34 to your computer and use it in GitHub Desktop.
class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('A name was submitted: ' + this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment