Based on React's docs an error boundary component should be a class component and it should have these two methods:
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
// You can also log the error to an error reporting service
logErrorToMyService(error, errorInfo);
}
The point is, we want to see the call stack in the development environment in the UI too.
But React says that we should not set state in componentDidCatch as it's going to be deprecated.
How can get errorInfo in getDerivedStateFromError?