Failing Gracefully: Error Boundaries in React
summary
Error boundaries are React class components using getDerivedStateFromError and componentDidCatch to render a fallback UI and log to services like sentry; they catch errors in rendering, constructors and lifecycle methods but not async code or event handlers and they don’t work on server rendering. Example: a dashboard of many widget components wraps each widget in its own boundary and implements a bubbling counter so when a threshold number of widget errors occurs the parent boundary renders a single fallback. The react reactor boundary library adds a Boundary component, an HOC and a useErrorHandler hook that can invoke the nearest boundary (useful for event handlers and Apollo error objects).
AI-written summary · about
