Don't hoist static getDerivedStateFromProps.
See original GitHub issueIn preparation for React 16.3, exclude getDerivedStateFromProps
from hoisted static methods. Currently it prints a warning, Warning: Connect(Component): Defines both componentWillReceiveProps() and static getDerivedStateFromProps() methods. We recommend using only getDerivedStateFromProps().
if the Component uses new API.
It also can totally break the app if Component.getDerivedStateFromProps uses some nested objects that are passed by Connect, because they are undefined on Connect and we get error Can not read property foo of undefined
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Why getDerivedStateFromProps is called after setState?
So I set another variable to check is that prop received for the first time. this.state={flag:true}. In getderivedstatefromprops static ...
Read more >React.js static getDerivedStateFromProps() - GeeksforGeeks
getDerivedStateFromProps (props, state) is a static method that is called just before render() method in both mounting and updating phase in ...
Read more >You Probably Don't Need Derived State – React Blog
The getDerivedStateFromProps bugfix in 16.4 makes derived state more predictable, so the results of misusing it are easier to notice.
Read more >Get derived state from props in React 16.3 - YouTube
This video talks about the changes coming up on the different component lifecycle hooks in React 16.3. Watch it to dive into the...
Read more >Writing Resilient Components - Overreacted
But I don't think style guides capture those principles well. ... And the “safer” getDerivedStateFromProps method is clunky.
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
Thanks! Actually I just realized it doesn’t affect us at FB (it was updated to 5.x). But I’m pretty sure there are still people on 4.x and it would be nice to let them upgrade React.
And done!
npm i react-redux@previous
or 4.4.9.