mcpField
R
react-error-handling

react-error-handling

github.com/oakossDevelopment20126 installsUpdated 10w ago
Repository

About react-error-handling

A skill for React developers implementing error boundaries and recovery behavior in component trees. It covers fallback UIs, reset patterns, and logging, while clarifying which errors boundaries do not catch.

Key features

  1. 01Class and function error boundaries
  2. 02Fallback UI patterns
  3. 03Manual and automatic reset
  4. 04Error logging guidance
  5. 05Nested boundary placement
  6. 06Suspense error handling

Use cases

  1. 01Isolate crashes in a feature section
  2. 02Offer retry after a rendering error
  3. 03Log component errors for monitoring

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/oakoss/agent-skills --skill react-error-handling

After installing, type/react-error-handlingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
boundary-placement.md
class-boundaries.md
fallback-patterns.md
react-error-boundary.md
reset-recovery.md

Details

From the project README

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

Comments

Markdown supported