Skip to main content
skill CX Codex

react-error-handling — Claude Code skill: setup and patterns

react-error-handling guides agents on React error boundaries and fallback interfaces to prevent component rendering failures from crashing the whole page.

MIT 134 installs ★ 29 updated 2026-08-17

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add oakoss/agent-skills --skill react-error-handling -a claude-code
Open on GitHub

What react-error-handling does

The skill outlines patterns for handling rendering exceptions via native class boundaries or the react-error-boundary package. It details how to configure error logging with onError, integrate with Suspense, and trigger state recovery using resetErrorBoundary or resetKeys.

Error boundaries cannot catch errors inside event handlers, setTimeout callbacks, or server-side rendering phases. Standard try/catch blocks remain mandatory for events. For route-level error boundaries in applications with TanStack Router, the skill delegates handling to the tanstack-router skill.

What it helps with

  • implement fallback UIs with retry buttons using react-error-boundary
  • isolate widget crashes to prevent complete layout failures
  • create class-based boundaries with getDerivedStateFromError and componentDidCatch
  • forward caught rendering errors to observability services

Example prompts for the agent

  • Wrap this chart component with react-error-boundary and provide a retry button
  • Build a class error boundary that updates state purely in getDerivedStateFromError
  • Configure resetKeys on our fallback UI to auto-reset when the item ID prop changes

How to install react-error-handling

1Skills CLI (Vercel)

npx skills add oakoss/agent-skills --skill react-error-handling -a claude-code

2Manually: put the files in place

~/.claude/skills/react-error-handling/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/react-error-handling/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about react-error-handling

How to install react-error-handling in Claude Code?

Run npx skills add oakoss/agent-skills --skill react-error-handling -a claude-code in your terminal.

What does react-error-handling do?

It provides agents with practical implementation rules for React error boundaries, fallback UI components, and recovery flows.

Does this handle event handler exceptions?

No. React error boundaries only intercept errors during rendering, in lifecycle methods, and inside child constructors. Event handlers require regular try/catch blocks.

Source text

SKILL.md · MIT
---
name: react-error-handling
description: '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.'
license: MIT
metadata:
  author: oakoss
  version: '1.0'
  source: 'https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary'
user-invocable: false
---

# 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

| Pattern               | API                                                        | Key Points                                 |
| --------------------- | ---------------------------------------------------------- | ------------------------------------------ |
| Class boundary        | `getDerivedStateFromError` + `componentDidCatch`           | Manual implementation, full control        |
| Function boundary     | `<ErrorBoundary FallbackComponent={...} />`                | Uses react-error-boundary library          |
| Reset mechanism       | `resetErrorBoundary()` or `resetKeys={[dep]}`              | Auto-reset on state change or manual retry |
| Error logging         | `onError={(error, info) => log(error)}`                    | Log to analytics or monitoring service     |
| Fallback component    | `FallbackComponent={MyFallback}`                           | Receives error and resetErrorBoundary      |
| Inline fallback       | `fallback={<div>Error occurred</div>}`                     | Static JSX, no error details               |
| Render prop fallback  | `fallbackRender={({ error, reset }) => <UI />}`            | Dynamic fallback with error access         |
| Nested boundaries     | Wrap at multiple tree levels                               | Granular error isolation                   |
| Route-level boundary  | TanStack Router `errorComponent`                           | Delegate to tanstack-router skill          |
| Suspense integration  | Wrap Suspense boundaries for async errors                  | Catch errors thrown by Suspense            |
| Event handler errors  | `try/catch` in handler, not error boundary                 | Boundaries don't catch event errors        |
| useErrorBoundary hook | `const { showBoundary, resetBoundary } = useErrorBoundary` | Manually trigger boundary from child       |

## Common Mistakes

| 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 |

## 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

- [Class-based error boundaries](references/class-boundaries.md)
- [react-error-boundary library](references/react-error-boundary.md)
- [Fallback UI patterns](references/fallback-patterns.md)
- [Reset and recovery patterns](references/reset-recovery.md)
- [Error boundary placement strategies](references/boundary-placement.md)

© oakoss · MIT · oakoss/agent-skills

Similar skills

All skills for Frontend and UI →

From the same set106

The whole set →
vite A skill for Vite work: config file, plugins, dev server, build output, SSR and env variables. Useful when the agent edits vite.config.ts in your project. CX Codex +1 138installs postgres-tuning postgres-tuning — a skill for Claude Code, Codex, Cursor and other agents that provides PostgreSQL 17/18+ performance tuning guidance. Covers async I/O, query plan forensics, index strategy, autovacuum, pgvector, and connection pooling. CX Codex +1 136installs tanstack-db Get guidance on TanStack DB collections, live queries, and optimistic writes. Useful when a UI needs reactive local data or explicit sync with a backend. CX Codex +1 136installs prompt-engineering prompt-engineering is a Claude Code skill for prompt design, covering reasoning chains, ReAct loops, system prompt layouts, extended thinking and context trimming. CX Codex +1 135installs frontend-builder The frontend-builder skill guides React and Next.js UI work, from component structure to forms and error handling. Use it when starting a web app or deciding how its frontend should be organized. CX Codex +1 134installs mise Teaches the agent to work with mise, the polyglot tool version manager, environment variable manager, and task runner. CX Codex +1 133installs data-visualizer data-visualizer guides chart and dashboard development using Recharts, Chart.js, or D3.js with built-in accessibility rules. CX Codex +1 133installs knowledge-base-manager knowledge-base-manager is a Claude Code skill for choosing a document, graph, or hybrid knowledge-base design and planning its maintenance. It covers content curation, quality checks, and versioning. CX Codex +1 131installs

Project sponsors

Companies that keep this analytics open