react-error-boundary

Reusable React error boundary component that catches rendering errors and shows a fallback UI.

Library
npm
v6.1.6
7,994 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
78 /100 Good
Development Activity 84
Maintenance 72
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 88
Code Quality 90
Innovation 92
Learning Curve 88

react-error-boundary is a small, dependency-free React library that wraps React’s error boundary API in an ergonomic, reusable component. Drop an ErrorBoundary around any part of your component tree to catch errors thrown while rendering and display a fallback UI instead of a blank screen or a crashed app.

Beyond the core component, it ships a useErrorBoundary hook for forwarding event-handler and async errors to the nearest boundary, a withErrorBoundary higher-order component, reset keys and imperative reset for recovery, and full TypeScript types. It supports every React renderer, including React DOM and React Native, and works with React 18 and 19.

What You Get

  • An ErrorBoundary component supporting three fallback strategies: static fallback, fallbackRender render prop, and FallbackComponent.
  • A useErrorBoundary hook to forward event-handler and async errors to the nearest boundary and to imperatively reset it.
  • A withErrorBoundary higher-order component for wrapping components without extra JSX nesting.
  • resetKeys plus an imperative resetErrorBoundary API and onError / onReset callbacks for logging and recovery.
  • First-class TypeScript types and support for React 18 and 19 across all renderers, including React Native.

Common Use Cases

  • Preventing a single component’s render error from crashing the entire application.
  • Showing a friendly retry UI when a widget, route, or dashboard panel fails to render.
  • Logging render errors to an external monitoring service via the onError callback.
  • Recovering from an error automatically when relevant state changes using resetKeys.
  • Forwarding errors from event handlers or async callbacks to a boundary with useErrorBoundary.

Under The Hood

Architecture — The core is a single class component, ErrorBoundary in lib/components/ErrorBoundary.tsx, that uses React’s getDerivedStateFromError to flip a discriminated-union state to { didCatch: true, error } and componentDidCatch to invoke the onError callback. Its render method selects among fallback, fallbackRender, and FallbackComponent, throwing the original error if none is provided, and always wraps children in an ErrorBoundaryContext.Provider so descendants can read didCatch, error, and resetErrorBoundary. componentDidUpdate compares resetKeys with a hasArrayChanged helper (guarded against resetting on the first update after catching) to auto-recover. The useErrorBoundary hook (lib/hooks/useErrorBoundary.ts) reads that context to forward async/handler errors, and withErrorBoundary (lib/utils/withErrorBoundary.ts) provides an HOC wrapper.

Tech Stack — Written in TypeScript targeting React 18 or 19 as the sole peer dependency, with zero runtime dependencies. The library entry point lib/index.ts is marked "use client" and re-exports the component, context, hook, HOC, and getErrorMessage utility alongside their types. Bundling is handled by Vite (vite.config.ts) emitting ESM and CJS builds plus .d.ts types via vite-plugin-dts; the repo also contains a full Vite + react-router documentation site under src/.

Code Quality — Types are the standout: lib/types.ts models the mutually exclusive fallback props as a discriminated union (ErrorBoundaryPropsWithFallback | ...WithComponent | ...WithRender) using never guards so invalid combinations fail at compile time. Test coverage is present and colocated — ErrorBoundary.test.tsx, useErrorBoundary.test.tsx, and withErrorBoundary.test.tsx — run under Vitest with Testing Library and jsdom, with vitest-fail-on-console enforcing clean output. Naming is explicit and the code is small, readable, and consistently formatted with Prettier and ESLint.

API Design — The public surface is deliberately minimal and ergonomic: one component with three well-documented fallback strategies, a hook, and an HOC cover the common cases with little boilerplate. JSDoc on every prop, a dedicated documentation site, and clear guidance on what errors boundaries do and do not catch make the developer experience excellent, and the discriminated-union typing means editors surface the right props for the chosen fallback strategy.

Used by 49 apps in this directory

Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,443

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
57
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 2 months ago
JavaScript
65%
Other

GDevelop

Design Tools · Developer Tools · Game Development

27,961

No-code, open-source game engine for building 2D, 3D and multiplayer games — publish to iOS, Android, Steam and the web.

View details
93
Repo Health
82
Technical
61
Dependency
Built with
JavaScript 65%
C++ 22%
TypeScript 11%
Updated 6 days ago
TypeScript
63%
MIT

Ghost

Blogging · CMS

55,598

Open source headless Node.js CMS for professional publishing, paid memberships, and newsletters with a fully owned audience.

View details
96
Repo Health
85
Technical
64
Dependency
Built with
TypeScript 63%
JavaScript 35%
Updated 6 days ago
TypeScript
98%
Other

GrowthBook

Ab Testing Experimentation · Analytics · Developer Tools

8,527

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

9,048

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
86
Repo Health
67
Technical
67
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
97%
MIT

HyperDX

Analytics · Developer Tools · Monitoring

9,963

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
89
Repo Health
83
Technical
64
Dependency
Built with
TypeScript 97%
Updated 5 days ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Python
71%
MIT

Langflow

AI Agents · AI Development

155,973

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
64
Dependency
Built with
Python 71%
TypeScript 21%
Updated 5 days ago
TypeScript
96%
AGPL 3.0

Libra AI

AI Development · No Code Platforms

1,695

Open-source AI-powered platform that generates and deploys full-stack web applications from natural language prompts, built natively for Cloudflare Workers.

View details
31
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 years ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers