An error boundary is React's try/catch for the render tree. When a descendant throws during render, the nearest boundary catches it and shows a fallback. It's the only place in 2026 where you'll write a class component on purpose.
What an error boundary catches
An error boundary catches errors thrown during render of any descendant. It does NOT catch:
- Errors in event handlers (handle them with try/catch inline).
- Errors in setTimeout / promise rejections that don't surface in render (handle them at the source).
- Errors in the boundary itself (you need a parent boundary for that).
- Server-side render errors (handled by the framework, not the boundary).
Combined with Suspense for loading and use() for data, error boundaries cover the error third of the loading/error/success triad.
The class shape
An error boundary needs getDerivedStateFromError (sets fallback state when a child throws) and componentDidCatch (logs the error to your reporting service). Write it once, reuse everywhere.
The react-error-boundary library
The npm package react-error-boundary exports a polished version: <ErrorBoundary FallbackComponent={...} onError={...}>. It also gives you useErrorBoundary for triggering boundaries from inside async code that wouldn't otherwise reach them. Most apps use this library over hand-rolling.
Reset behavior
Once a boundary catches an error, it stays in the error state until something resets it. The library's resetErrorBoundary prop on the fallback component handles this — typically wired to a 'try again' button.