React | Error Boundaries and Debugging | Question 9

Last Updated :
Discuss
Comments

What is the role of getDerivedStateFromError() in an error boundary?

JavaScript
function App() {
    return (
        <ErrorBoundary>
            <div>{undefinedVar}</div>
        </ErrorBoundary>
    );
}


Trigger re-render

Log the error

Update state on error

Display fallback UI

Share your thoughts in the comments