I'm using error boundaries in React and everything appears to be working as expected— getDerivedStateFromError gets called when there is an underlying error, and then I return a state to denote that there is an error.
But what happens after the component is no longer in an error state? I've tried using getDerivedStateFromProps to return a non-error state, but it ends up going into an infinite loop.
For example
static getDerivedStateFromProps()
{
return {
hasError: false
}
}
static getDerivedStateFromError(error) {
return {
hasError: true
};
}
It seems like React should only call one of those methods, not both. Any ideas on how to take a component in and out of an error state?