`componentWillReceiveProps()` does not trigger for new context changes
See original GitHub issueThe componentWillReceiveProps()
method only triggers if props change. However, there are situations where the context changes, but the props do not, but this method does not trigger. It makes it really difficult to alter the state before an update, as we can’t do this in componentWillUpdate()
.
Perhaps a new method, like componentWillReceiveContext()
can be added, or the previous componentWillReceiveProps()
can simply be renamed to something like componentWillReceive()
, which is always called if any prop/state/context has changed.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:6 (6 by maintainers)
Top Results From Across the Web
componentWillReceiveProps not firing when the state gets ...
So, I have an action and a reducer to pass the status of the button through. This is working fine except that the...
Read more >componentWillReceiveProps Not Triggered After Mounting
componentWillReceiveProps isn't triggered after the node is put on scene. ... and acting upon changes; not triggering it at mounting (where there are...
Read more >React.Component
Use shouldComponentUpdate() to let React know if a component's output is not affected by the current change in state or props. The default...
Read more >Lifecycle deprecated/New Methods - React Training
A setState used in this function is “free” and will not trigger a re-render. DO ... whenever the props they receiver, their state...
Read more >Class: MinimizeButton - Finsemble
Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In fact,
componentWillReceiveProps
does trigger whencontext
changes. Here’s an example fiddle of how it can be used and accomplished:https://jsfiddle.net/bzytthat/
Read more about using
context
in lifecycle methods: http://facebook.github.io/react/docs/context.html#referencing-context-in-lifecycle-methodsI did some debugging in the React source, and it seems to always trigger true for this clause. https://github.com/facebook/react/blob/3b96650e39ddda5ba49245713ef16dbc52d25e9e/src/renderers/shared/reconciler/ReactCompositeComponent.js#L657
Which seems to agree with my original issue, that the
componentWillReceiveProps()
isn’t being called because the props haven’t changed.