Last active
August 23, 2018 14:28
-
-
Save SangeetAgarwal/671a75d19d06999b28728605f5741326 to your computer and use it in GitHub Desktop.
avoid-deep-merge
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
updateState({target}) { | |
this.setState(prevState => { | |
return { | |
user: { | |
...prevState.user, | |
[target.name]: target.value, | |
address: { | |
// first lay out all the properties within the address object | |
...prevState.user.address, | |
// now, overwrite the properties that need to be overwritten... | |
// each of the below statements are optional depending upon what needs to be overwritten | |
// street: 'a new street' | |
// city: 'a new city' | |
} | |
} | |
} | |
}, () => doSomething()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment