question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't hoist static getDerivedStateFromProps.

See original GitHub issue

In 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:closed
  • Created 6 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Mar 21, 2018

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.

0reactions
timdorrcommented, Mar 21, 2018

And done! npm i react-redux@previous or 4.4.9.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found