Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to update nested state properties #1101

Open
dandv opened this issue Jul 30, 2018 · 6 comments
Open

Document how to update nested state properties #1101

dandv opened this issue Jul 30, 2018 · 6 comments

Comments

@dandv
Copy link
Contributor

@dandv dandv commented Jul 30, 2018

In setState, what should one return from the updater function in order to update a nested property of the state? This isn't documented, and it trips a lot of people:

https://stackoverflow.com/questions/18933985/this-setstate-isnt-merging-states-as-i-would-expect
https://stackoverflow.com/questions/43040721/how-to-update-a-nested-state-in-react
https://stackoverflow.com/questions/34071160/how-to-update-object-in-react-js
etc.

@zacharymorel
Copy link

@zacharymorel zacharymorel commented Jan 22, 2019

I second this, I would love to read some detailed docs from y'all.

@cbdeveloper
Copy link

@cbdeveloper cbdeveloper commented Jan 30, 2019

@yvesgurcan
Copy link

@yvesgurcan yvesgurcan commented Jun 29, 2019

Hey guys! I opened a PR to document how to handle nested state properties. First contribution to the ReactJS.org project :)

geetesh911 added a commit to geetesh911/reactjs.org that referenced this issue Oct 18, 2020
@bk973
Copy link

@bk973 bk973 commented Feb 5, 2021

It's better to write your updater function to return new state based on old state. If you do this, then updating state for nested data is pretty straightforward.

@silver-snoopy
Copy link

@silver-snoopy silver-snoopy commented Feb 28, 2021

Has this issue been abandoned? I can pick it up and write the documentation based on the previous PR.

@yvesgurcan
Copy link

@yvesgurcan yvesgurcan commented Apr 8, 2021

Hey @silver-snoopy, you're welcome to work based on the previous PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants