Last active
November 4, 2017 03:44
-
-
Save michaelmcshinsky/6291256b0f7edac1ad247c8805296c0c to your computer and use it in GitHub Desktop.
Useful snippets for handle change events that handle multiple situations fast and effectively
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
// V.1 | |
// Use Case: Input, Checkbox & Select Handling | |
handleChange = (e) => { | |
this.setState({[e.target.name]: e.target.type === 'checkbox' ? e.target.checked : e.target.value; | |
} | |
// V.2 | |
// Use Case: State Object Handling for: Input, Checkbox & Select | |
handleChange = (e) => { | |
// your target object | |
let obj = this.state.obj; | |
obj[e.target.name] = e.target.type === 'checkbox' ? e.target.checked : e.target.value; | |
this.setState({obj}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment