shallow renderer: wrong initial state passed to getDerivedStateFromProps
See original GitHub issueDemonstrated 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:
- Created 5 years ago
- Reactions:1
- Comments:11 (9 by maintainers)
Top 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 >
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
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.
Oops, missed that. Thanks.