← All Quizzes
What are error boundaries in React and what do they catch?
Explanation
Error boundaries are React components that catch JavaScript errors in their child component tree during rendering, lifecycle methods, and constructors. They use componentDidCatch (for side effects like logging) and getDerivedStateFromError (to update state and show fallback UI). Error boundaries do NOT catch errors in event handlers, async code, or setTimeout callbacks. For those, use try-catch. Error boundaries prevent a single component error from breaking the entire app.