Skip to content

Document that syncing props and state is usually a bad idea #337

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

Open
gaearon opened this issue Nov 24, 2017 · 10 comments
Open

Document that syncing props and state is usually a bad idea #337

gaearon opened this issue Nov 24, 2017 · 10 comments

Comments

@gaearon
Copy link
Member

gaearon commented Nov 24, 2017

We used to have a "tip" about this on the old website (a few years ago), but not anymore.

I think maybe we need to revive that section because too many people attempt to derive state from props—either in constructor or cWRP—without realizing they could just do this work in render. In 90% of cases that's exactly what they need to do.

See also https://mobile.twitter.com/EntriaTech/status/934139022204653569.

@jyash97
Copy link
Contributor

jyash97 commented Nov 24, 2017

Hey @gaearon can I take this? Could you tell what to we need to add ?

@alexkrolick
Copy link
Collaborator

@jyash97 the issue is yours!

I've added an "in-progress" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let me know so that I can remove the label and free it up for someone else to claim.

As far as what to add, how about starting with a disclaimer in State and Lifecycle and FAQ: State?

@jyash97
Copy link
Contributor

jyash97 commented Nov 25, 2017

#341
Hey @alexkrolick I have done the changes, please have a look at it

@bvaughn
Copy link
Contributor

bvaughn commented Nov 29, 2017

Hey @jyash97. The outcome of #341 didn't actually end up related to this issue, but rather to #351, so I'm going to mark this issue as no longer in progress. If you'd like to send another PR that implements the suggestion from this issue though, let us know and we'll mark it back in progress. 😄

@jyash97
Copy link
Contributor

jyash97 commented Nov 30, 2017

@bvaughn
Can you have a look at the first commit of #341, I added topics like what should come in State, is this the good way of tackling this issue?

@bvaughn
Copy link
Contributor

bvaughn commented Nov 30, 2017

At a glance the section "What Shouldn’t Go in State?" seems like what this issue is asking for.

@jyash97
Copy link
Contributor

jyash97 commented Nov 30, 2017

Okay let me try one more time to update this content

@bvaughn
Copy link
Contributor

bvaughn commented Dec 4, 2017

I think that's just another explanation of why state and props are different but this issue is asking for more of a warning about why syncing props to state is generally unnecessary.

jyash97 added a commit to jyash97/reactjs.org that referenced this issue Jan 1, 2018
@jyash97
Copy link
Contributor

jyash97 commented Jan 1, 2018

@bvaughn
Sorry for being late on the issue, but have updated it now.

jhonmike pushed a commit to jhonmike/reactjs.org that referenced this issue Jul 1, 2020
* Translating testing-environments docs

* Apply suggestions from code review

Co-Authored-By: Bruno Vercelino da Hora <[email protected]>

* Removing italic markup from mock word
BetterZxx pushed a commit to BetterZxx/react.dev that referenced this issue Mar 21, 2023
* docs(cn): fix errors in hooks-intro.md

* Update hooks-intro.md

* Update hooks-intro.md
@rickhanlonii
Copy link
Member

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

No branches or pull requests

5 participants