Skip to content

Instantly share code, notes, and snippets.

@geetotes
Created March 15, 2017 21:37
Show Gist options
  • Save geetotes/b8cd2097a9fd4e55334c79ac45d5da8a to your computer and use it in GitHub Desktop.
Save geetotes/b8cd2097a9fd4e55334c79ac45d5da8a to your computer and use it in GitHub Desktop.
class GenericControlledForm extends React.Component {
constructor() {
super();
this.state {
name: '',
occupation: ''
};
this._onChange = this._onChange.bind(this);
}
_onChange(e) {
this.setState({
[e.target.name]: e.target.value
});
}
render() {
return (
<form>
<input name='name' onChange={this._onChange} value={this.state.name} />
<input name='occupation' onChange={this._onChange} value={this.state.occupation} />
</form>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment