-
Notifications
You must be signed in to change notification settings - Fork 49.3k
Open
Description
In the render
block of a ErrorBoundary
component the props.children
is remounted when getDerivedStateFromError
derives a new state (or componentDidCatch
sets a state).
Is this a special case ? Setting the state in any other manner (e.g componentDidUpdate
doesn't have this behavior). I don't see this behavior documented in the React docs.
Thanks!
React version: 18.2.0 (Happens on 17.0.2 as well).
Steps To Reproduce
- In the code example increment the counter past 5 and the child component unmounts and mounts, the child state also resets
Link to code example: https://codesandbox.io/s/nifty-platform-wub9wn?file=/src/App.tsx
The current behavior
props.children
unmounts and mounts.
The expected behavior
props.children
rerenders.