Last active
June 11, 2017 19:41
-
-
Save coryhouse/f31ab2ca81ca45195a4e4889cade0e11 to your computer and use it in GitHub Desktop.
Handling immutable state in React with immutability-helper
This file contains hidden or 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
// Import at the top: | |
import update from 'immutability-helper'; | |
updateState({target}) { | |
let user = update(this.state.user, {$merge: {[target.name]: target.value}}); | |
this.setState({user}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment