Skip to content

Instantly share code, notes, and snippets.

@izniburak
Forked from nanotroy/eventhandler.js
Created July 29, 2019 22:19
Show Gist options
  • Save izniburak/8e6c10ec2ce2a3b45a79242c02b197c2 to your computer and use it in GitHub Desktop.
Save izniburak/8e6c10ec2ce2a3b45a79242c02b197c2 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