Complete Error Boundary Method
Fill in the Blank Medium
Question
Fill in the blank with the method that updates state on error.
Code
class ErrorBoundary extends React.Component {
static _____(error) {
return { hasError: true };
}
render() {
if (this.state.hasError) return <h1>Error!</h1>;
return this.props.children;
}
}
Hint
This static method is called when an error is thrown during render.
Explanation
getDerivedStateFromError is a static lifecycle method called when a descendant throws an error. It receives the error and returns a state update to show the fallback UI.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.