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

Added additional detail to "props-in-getInitialState" anti-pattern doc #5849

Merged
merged 1 commit into from
Jan 14, 2016

Conversation

david0178418
Copy link
Contributor

While seemingly self-explanatory, this clarifies the reasons props usage in getInitialState might be considered an antipattern.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@@ -11,7 +11,9 @@ next: dom-event-listeners.html
>
> This isn't really a React-specific tip, as such anti-patterns often occur in code in general; in this case, React simply points them out more clearly.

Using props, passed down from parent, to generate state in `getInitialState` often leads to duplication of "source of truth", i.e. where the real data is. Whenever possible, compute values on-the-fly to ensure that they don't get out of sync later on and cause maintenance trouble.
Using props, passed down from parent, to generate state in `getInitialState` often leads to duplication of "source of truth", i.e. where the real data is. This is because `getInitialState` is only invoked when the component is first created.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, could you clean up the first sentence and just remove the "passed down from parent" bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

While seemingly self-explanatory, this clarifies the reasons props usage in getInitialState might be considered an antipattern.
@facebook-github-bot
Copy link

@david0178418 updated the pull request.

@zpao
Copy link
Member

zpao commented Jan 14, 2016

Looks great, thanks!

zpao added a commit that referenced this pull request Jan 14, 2016
Added additional detail to "props-in-getInitialState" anti-pattern doc
@zpao zpao merged commit f1c1544 into facebook:master Jan 14, 2016
zpao added a commit that referenced this pull request Jan 28, 2016
Added additional detail to "props-in-getInitialState" anti-pattern doc
(cherry picked from commit f1c1544)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants