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.

shallow renderer: wrong initial state passed to getDerivedStateFromProps

See original GitHub issue

Demonstrated in https://github.com/airbnb/enzyme/pull/2027 - when gDSFP returns a state change, cDU does not seem to be called by the shallow renderer. I’m not sure how to make a simple test case; but the identical enzyme tests pass for mount (ie, when using React itself) but fail for shallow (when using the shallow renderer). enzyme doesn’t have any logic for calling or interacting with getDerivedStateFromProps, so I suspect it’s not an issue with enzyme (but it might be!)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Mar 24, 2019

Hmm - now I can’t reproduce it even on my original sandboxes 😕 I see the same minor discrepancy as you when I comment out the state assignment in the Demo constructor, and while that might be nice to fix it’s probably not worth the effort.

I’m going to close this - I’ll comment here, or file a new issue, if I see anything else.

1reaction
gaearoncommented, Mar 19, 2019

Oops, missed that. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why getDerivedStateFromProps does not allow to re-render ...
When a make an update to the component's state, the state changes (and the component did after updated) but still renders the previous...
Read more >
You Probably Don't Need Derived State – React Blog
getDerivedStateFromProps exists for only one purpose. It enables a component to update its internal state as the result of changes in props.
Read more >
React Gotchas, Anti-Patterns, and Best Practices | by Steven Li
The suggestion is to use getDerivedStateFromProps(props, state) for updating the state based on new props . But note that getDerivedStateFromProps is a static ......
Read more >
React.Component - IPFS文档
getDerivedStateFromProps is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object...
Read more >
A Deep Dive into React Class Lifecycle Methods
getDerivedStateFromProps is invoked right before calling the render method, both on the initial mount and on subsequent updates. This method ...
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