- Home
- /
- Tutorials
- /
- React Tutorial
- /
- Error Boundaries
Data and Errors
Error Boundaries
An uncaught error during render does not break one component - React unmounts the entire tree, and the user gets a blank page. An error boundary is the only thing that stops that.
Why a blank page
React cannot know which parts of a half-rendered tree are still trustworthy, so it takes the safe option and removes everything. That is deliberate, and it means one careless user.name on a null user can take down the whole app.
A boundary catches it
An error boundary is a component that catches errors thrown while rendering anything below it and shows a fallback instead. It is the one thing still written as a class - there is no hook equivalent, because the lifecycle it needs has none.
A boundary and a crash
jsx
