-
Notifications
You must be signed in to change notification settings - Fork 45.8k
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
Blog post explains to verify prop mutations in componentWillReceiveProps #5790
Blog post explains to verify prop mutations in componentWillReceiveProps #5790
Conversation
@@ -148,6 +148,8 @@ componentWillReceiveProps: function(nextProps) { | |||
|
|||
> Note: | |||
> | |||
> It is **incorrect** for code executed during this lifecycle method to assume that props have changed. To understand why, read [A implies B does not imply B implies A](/react/blog/2016/01/08/A-implies-B-does-not-imply-B-implies-A.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of saying what's incorrect, I would suggest to make the explanation at the top more verbose. Now it just says: "Invoked when a component is receiving new props." That this sentence is formal logic is not obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make this point about it being incorrect abundantly clear, since people seem to make this assumption even after they are explicitly told that there is no guarantee that props have changed.
BTW, all sentences in the entire site should be interpreted logically; people should be careful in their parsing of all documentation. We work very hard to ensure that the documentation is as precise as possible, often spending hours nitpicking the choice of only a few words. I'll deemphasize the incorrectness to avoid hurting people's feelings, but I do want to call out the fact that it's a common mistake.
117465a
to
c85c566
Compare
+1 ;) |
c85c566
to
a596efa
Compare
author: jimfb | ||
--- | ||
|
||
The documentation for `componentWillReceiveProps` states that `componentWillReceiveProps` will be invoked when the props change as the result of a rerender. Some newbies assume this means "if `componentWillReceiveProps` is called, then the props must have changed", but that conclusion is logically incorrect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's never say "newbies" again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=define%3Anewbie
newbie - noun - an inexperienced newcomer to a particular activity.
Seems like the perfect word, though admittedly a little informal. But I don't feel strongly, so I'll change it :P.
5872c98
to
9a402eb
Compare
@jimfb updated the pull request. |
9a402eb
to
2d08123
Compare
@jimfb updated the pull request. |
👍 |
@zpao Can I get the green light on this one? Is it ready to go? |
author: jimfb | ||
--- | ||
|
||
The documentation for `componentWillReceiveProps` states that `componentWillReceiveProps` will be invoked when the props change as the result of a rerender. Some inexperienced users assume this means "if `componentWillReceiveProps` is called, then the props must have changed", but that conclusion is logically incorrect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/inexperienced users/people/
I'm sure plenty of people who have been using React for a while make that assumption as well. I don't see a good reason for qualifying who those people are.
2d08123
to
70938de
Compare
@jimfb updated the pull request. |
@zpao done. |
As per in person with @zpao, we're good-to-go on this one. |
Blog post explains to verify prop mutations in componentWillReceiveProps
Blog post explains to verify prop mutations in componentWillReceiveProps (cherry picked from commit a158405)
This seems to be a recurring question. People always want to know WHY we sometimes call
componentWillReceiveProps
even when the props haven't changed. I've seen this in several threads now.Blog post explains.