react-error-handling

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.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "react-error-handling" with this command: npx skills add oakoss/agent-skills

React Error Handling

Overview

Error boundaries catch JavaScript errors during rendering, in lifecycle methods, and in constructors of child components. They display fallback UIs instead of crashing the entire component tree. Error boundaries can only be implemented as class components in vanilla React, but the react-error-boundary library provides a convenient function component wrapper.

When to use: Component crashes, preventing error propagation to parent routes, graceful degradation, user-facing error states, error logging and monitoring.

When NOT to use: Event handler errors (use try/catch), async callbacks outside rendering (setTimeout, promises without Suspense), server-side rendering errors, errors in the boundary itself.

Quick Reference

PatternAPIKey Points
Class boundarygetDerivedStateFromError + componentDidCatchManual implementation, full control
Function boundary<ErrorBoundary FallbackComponent={...} />Uses react-error-boundary library
Reset mechanismresetErrorBoundary() or resetKeys={[dep]}Auto-reset on state change or manual retry
Error loggingonError={(error, info) => log(error)}Log to analytics or monitoring service
Fallback componentFallbackComponent={MyFallback}Receives error and resetErrorBoundary
Inline fallbackfallback={<div>Error occurred</div>}Static JSX, no error details
Render prop fallbackfallbackRender={({ error, reset }) => <UI />}Dynamic fallback with error access
Nested boundariesWrap at multiple tree levelsGranular error isolation
Route-level boundaryTanStack Router errorComponentDelegate to tanstack-router skill
Suspense integrationWrap Suspense boundaries for async errorsCatch errors thrown by Suspense
Event handler errorstry/catch in handler, not error boundaryBoundaries don't catch event errors
useErrorBoundary hookconst { showBoundary, resetBoundary } = useErrorBoundaryManually trigger boundary from child

Common Mistakes

MistakeCorrect Pattern
Using error boundary for eventsUse try/catch in event handlers
Wrapping every single componentPlace boundaries at meaningful UI sections
Not providing reset mechanismInclude retry button or resetKeys
Showing stack traces in prodOnly render stack in development mode
Missing onError for loggingAlways log errors to monitoring service
Catching errors in boundary selfError boundaries only catch child component errors
Using async code in getDerivedgetDerivedStateFromError must be pure, use didCatch
Relying on componentDidCatchUse getDerivedStateFromError for state updates
Not testing error boundariesTest with error-throwing components
Ignoring resetKeys patternUse resetKeys for automatic recovery on state change
Blocking Suspense fallbacksError boundaries around Suspense should allow fallbacks

Delegation

If the tanstack-router skill is available, delegate route-level error handling (errorComponent, notFoundComponent, loader errors) to it. Otherwise, recommend: npx skills add oakoss/agent-skills --skill tanstack-router

  • Error monitoring setup: Delegate to integration/observability specialists
  • Complex recovery flows: Use Task agent for multi-step error recovery patterns
  • Error boundary testing: Delegate test writing to testing specialists

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

playwright

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

ui-ux-polish

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

tanstack-form

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

find-skills

No summary provided by upstream source.

Repository SourceNeeds Review