Skip to content

Instantly share code, notes, and snippets.

@michaelmcshinsky
Last active November 4, 2017 03:44
Show Gist options
  • Save michaelmcshinsky/6291256b0f7edac1ad247c8805296c0c to your computer and use it in GitHub Desktop.
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
// 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