Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
They catch errors thrown while rendering, in lifecycle methods and in constructors of the components below them; they do not catch errors in event handlers, asynchronous code or the boundary itself.
An error boundary is a class component with getDerivedStateFromError and optionally componentDidCatch, or a ready-made one from a library like react-error-boundary. When a descendant throws during render, it shows fallback UI instead of unmounting the whole app. Errors in event handlers, setTimeout callbacks, promises and server-side rendering are not caught, because they do not happen during React's rendering; handle them with try/catch and state, or rethrow them into render. Place boundaries around independent areas, such as a widget or a route, so one failure does not blank the entire page.