-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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 a new lifecycle method componentWillReceiveContext() #5776
Conversation
…s dealing with changed context easier to manage.
I don't see how this would help with #2517 or #3973 - they seem orthogonal. More to the point, I don't think the solution is to add a new lifecycle here. The solution is to fix https://goo.gl/xWSesX to ensure |
@@ -145,6 +145,14 @@ void componentDidUpdate( | |||
) | |||
``` | |||
|
|||
Additionally, a new lifecycle method named `componentWillReceiveContext` is included, which is called after `componentWillReceiveProps`, but before the update occurs. This method will *always* be called if contexts are enabled, unlike `componentWillReceiveProps`, which is only called if props change. |
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.
There is no guarantee that componentWillReceiveProps
is called only when props change. The only guarantee is that componentWillReceiveProps
will be called if props change.
I'm ok with either keeping Regardless, there is definitely a disconnect in how |
@milesj My understanding is that the intended behavior is for |
Off the top of my head, we might be able to change this line here: https://github.com/facebook/react/blob/master/src/renderers/shared/reconciler/ReactCompositeComponent.js#L657 To do some kind of check that compares the previous and next contexts. if (prevParentElement === nextParentElement && (nextContext === emptyObject || !this.diff(nextContext, prevContext)) { Will give it a try. |
Fixed the other issue in this pull request: #5787 |
Going to close this since #5787 was accepted. |
I've been working with contexts a lot lately, and have run into a few issues where the current lifecycle isn't perfect. Specifically, I encounter certain situations where
componentWillReceiveProps
isn't triggered, even though the context has changed: #5756.This new lifecycle may help with certain situations regarding contexts, like the following issues: #2517 #3973