Created
June 10, 2019 16:56
-
-
Save nanotroy/9059667a99ecc6305e3b7d34aead94c3 to your computer and use it in GitHub Desktop.
This file contains 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 App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
foo: "", | |
bar: "", | |
}; | |
} | |
// Reusable for all inputs | |
onChange = e => { | |
const { | |
target: { value, name }, | |
} = e; | |
// name will be the state name | |
this.setState({ | |
[name]: value | |
}); | |
}; | |
render() { | |
return ( | |
<div> | |
<input name="foo" onChange={this.onChange} /> | |
<input name="bar" onChange={this.onChange} /> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment