What is an Error Boundary?
In the past, a JavaScript error inside a component would corrupt React’s internal state and cause the entire application to vanish (the 'White Screen of Death'). Error Boundaries are special components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the crashed component tree.
The Catch: Class Components Only
As of 2026, Error Boundaries must still be written as Class Components. There is no functional hook equivalent (like useError) because the lifecycle methods getDerivedStateFromError and componentDidCatch are unique to classes. Most developers write one 'Global' boundary and several 'Feature' boundaries.
What Error Boundaries Do NOT Catch
Error Boundaries are powerful but they are not a universal 'try-catch'. They specifically catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
- Event handlers: (e.g.,
onClickerrors). Use regular try/catch blocks here. - Asynchronous code: (e.g.,
setTimeoutorrequestAnimationFramecallbacks). - Server-side rendering.
- Errors thrown in the boundary itself (rather than its children).
Strategy: Granular Boundaries
Don't just wrap your App in one boundary. Wrap individual heavy features (like a Dashboard Chart or a Search Sidebar) so that if one fails, the rest of the application remains interactive.