Last active
December 19, 2019 20:00
-
-
Save dev-kperera/923a2264bb4e45c58be3785031d1b8f0 to your computer and use it in GitHub Desktop.
React setState with spread operator when you need to change values of state object item. Motivation: https://stackoverflow.com/questions/43638938/updating-an-object-with-setstate-in-react
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
this.setState(prevState => ({ | |
OBJECT_NAME: { | |
...prevState.OBJECT_NAME, | |
OBJECT_KEY : NEW_VALUE | |
}})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment