Only in class components
- If a component throws an error during rendering, React will crash the whole UI tree.
- Rely on class lifecycle methods that hooks do not have access to.
Hooks Don’t Have Error Boundaries
- Error boundaries rely on render phase lifecycle
- Hooks run after render
- React needs class lifecycle control for error recovery
Error Boundaries do:
- Catch errors during render
- Catch errors in lifecycle methods
- Catch errors in constructors of child components
- Show a fallback UI
- Prevent app from fully crashing
❌ NOT caught:
- Event handlers (
onClick)
- Async code (
setTimeout, fetch)
- Server-side rendering