-
-
Save izniburak/8e6c10ec2ce2a3b45a79242c02b197c2 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