Loading...
Loading...
React error boundaries and fallback UIs for catching rendering errors. Use when handling component crashes, displaying error states, implementing error recovery, or preventing full-page crashes. Use for ErrorBoundary, componentDidCatch, getDerivedStateFromError, error fallback, error recovery, crash handling, react-error-boundary library.
npx skill4agent add oakoss/agent-skills react-error-handlingreact-error-boundary| Pattern | API | Key Points |
|---|---|---|
| Class boundary | | Manual implementation, full control |
| Function boundary | | Uses react-error-boundary library |
| Reset mechanism | | Auto-reset on state change or manual retry |
| Error logging | | Log to analytics or monitoring service |
| Fallback component | | Receives error and resetErrorBoundary |
| Inline fallback | | Static JSX, no error details |
| Render prop fallback | | Dynamic fallback with error access |
| Nested boundaries | Wrap at multiple tree levels | Granular error isolation |
| Route-level boundary | TanStack Router | Delegate to tanstack-router skill |
| Suspense integration | Wrap Suspense boundaries for async errors | Catch errors thrown by Suspense |
| Event handler errors | | Boundaries don't catch event errors |
| useErrorBoundary hook | | Manually trigger boundary from child |
| Mistake | Correct Pattern |
|---|---|
| Using error boundary for events | Use try/catch in event handlers |
| Wrapping every single component | Place boundaries at meaningful UI sections |
| Not providing reset mechanism | Include retry button or resetKeys |
| Showing stack traces in prod | Only render stack in development mode |
| Missing onError for logging | Always log errors to monitoring service |
| Catching errors in boundary self | Error boundaries only catch child component errors |
| Using async code in getDerived | getDerivedStateFromError must be pure, use didCatch |
| Relying on componentDidCatch | Use getDerivedStateFromError for state updates |
| Not testing error boundaries | Test with error-throwing components |
| Ignoring resetKeys pattern | Use resetKeys for automatic recovery on state change |
| Blocking Suspense fallbacks | Error boundaries around Suspense should allow fallbacks |
If theskill is available, delegate route-level error handling (errorComponent, notFoundComponent, loader errors) to it. Otherwise, recommend:tanstack-routernpx skills add oakoss/agent-skills --skill tanstack-router
Task