Created
March 15, 2017 21:37
-
-
Save geetotes/b8cd2097a9fd4e55334c79ac45d5da8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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