Skip to content

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

Open
@gaearon

Description

@gaearon
Member

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.

Activity

jyash97

jyash97 commented on Nov 24, 2017

@jyash97
Contributor

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

alexkrolick

alexkrolick commented on Nov 24, 2017

@alexkrolick
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

jyash97 commented on Nov 25, 2017

@jyash97
Contributor

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

bvaughn

bvaughn commented on Nov 29, 2017

@bvaughn
Contributor

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

jyash97 commented on Nov 30, 2017

@jyash97
Contributor

@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

bvaughn commented on Nov 30, 2017

@bvaughn
Contributor

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

jyash97

jyash97 commented on Nov 30, 2017

@jyash97
Contributor

Okay let me try one more time to update this content

bvaughn

bvaughn commented on Dec 4, 2017

@bvaughn
Contributor

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.

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bvaughn@gaearon@alexkrolick@rickhanlonii@jyash97

        Issue actions

          Document that syncing props and state is usually a bad idea · Issue #337 · reactjs/react.dev