Skip to content

Instantly share code, notes, and snippets.

@nanotroy
Created June 10, 2019 16:56
Show Gist options
  • Save nanotroy/9059667a99ecc6305e3b7d34aead94c3 to your computer and use it in GitHub Desktop.
Save nanotroy/9059667a99ecc6305e3b7d34aead94c3 to your computer and use it in GitHub Desktop.
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