react-error-boundary and react-error-overlay both address error handling in React applications, but they serve distinct roles in the error management lifecycle. react-error-boundary is a reusable component wrapper that catches JavaScript errors anywhere in the child component tree, logs those errors, and displays a fallback UI instead of crashing the whole app. It is designed for both development and production use. react-error-overlay, on the other hand, is a utility often bundled with development tooling like Create React App. It focuses on rendering a detailed error report (the "red screen of death") directly in the browser during development, helping developers debug stack traces and build errors without checking the console.
Both react-error-boundary and react-error-overlay help manage errors in React, but they solve different problems. One keeps your app running when things break; the other helps you see why they broke while you are coding. Let's look at how they work and when to use each.
react-error-boundary focuses on error recovery.
// react-error-boundary: Catch and fallback
import { ErrorBoundary } from 'react-error-boundary';
function App() {
return (
<ErrorBoundary fallback={<div>Something went wrong</div>}>
<UserProfile />
</ErrorBoundary>
);
}
react-error-overlay focuses on error reporting.
// react-error-overlay: Report error to overlay
import { reportBuildError } from 'react-error-overlay';
// Usually called by tooling when a build or runtime error occurs
try {
riskyOperation();
} catch (err) {
reportBuildError(err);
// Shows the red screen with stack trace
}
react-error-boundary is used as a React Component.
fallback, onError, and resetErrorBoundary.// react-error-boundary: Component usage
import { ErrorBoundary } from 'react-error-boundary';
function Fallback({ error, resetErrorBoundary }) {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre>{error.message}</pre>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
);
}
<ErrorBoundary FallbackComponent={Fallback}>
<Dashboard />
</ErrorBoundary>
react-error-overlay is used as a JavaScript Utility.
// react-error-overlay: Utility usage
import { dismissBuildError } from 'react-error-overlay';
// Dismiss the overlay when the error is fixed
function onFixConfirmed() {
dismissBuildError();
// Removes the red screen from the DOM
}
react-error-boundary works in Production and Development.
onError callback.// react-error-boundary: Logging in production
import { ErrorBoundary } from 'react-error-boundary';
function logError(error, info) {
// Send to monitoring service
console.error('Production error:', error);
}
<ErrorBoundary onError={logError} fallback={<div>Offline</div>}>
<CheckoutProcess />
</ErrorBoundary>
react-error-overlay is designed for Development Only.
// react-error-overlay: Dev-only check
if (process.env.NODE_ENV === 'development') {
// Only import and use in dev
const { reportBuildError } = require('react-error-overlay');
reportBuildError(error);
}
react-error-boundary gives you full control over the UI.
fallback prop.// react-error-boundary: Custom styled fallback
<ErrorBoundary
fallback={
<div className="p-4 bg-red-100 text-red-800 rounded">
We encountered an issue. Please refresh.
</div>
}
>
<Widget />
</ErrorBoundary>
react-error-overlay has a fixed, opinionated style.
// react-error-overlay: Limited customization
// The overlay injects its own styles and DOM structure
// Hard to change without modifying the package source or CSS injection
reportBuildError(error);
// Renders a predefined red overlay
react-error-boundary is a standalone library.
// react-error-boundary: Universal support
// Works in Next.js, Create React App, Vite, etc.
import { ErrorBoundary } from 'react-error-boundary';
react-error-overlay is tied to Build Tooling.
react-dev-utils.// react-error-overlay: Tooling dependency
// Often installed as a transitive dependency via CRA
// Direct usage is rare for app developers
import { setEditorHandler } from 'react-error-overlay';
While they serve different ends of the error handling spectrum, they share some underlying concepts.
// Both catch errors that would otherwise break the UI tree
// react-error-boundary catches via componentDidCatch
// react-error-overlay catches via window.onerror or unhandled promise rejection
npm install or yarn add.// Installation commands
npm install react-error-boundary
npm install react-error-overlay
react-error-boundary logs errors via callbacks.react-error-overlay displays errors visually.// react-error-boundary logging
onError={(error) => console.log(error)}
// react-error-overlay visual
// Shows file name and line number in browser
| Feature | react-error-boundary | react-error-overlay |
|---|---|---|
| Primary Goal | š”ļø Prevent app crashes (Recovery) | š¢ Show error details (Reporting) |
| Usage Type | š§© React Component Wrapper | āļø JavaScript Utility Functions |
| Environment | š Production & Development | š ļø Development Only |
| UI Control | šØ Fully Customizable Fallback | š Fixed "Red Screen" Style |
| Target User | š¤ End Users (Friendly UI) | šØāš» Developers (Stack Traces) |
| Ecosystem | š General React Community | šļø Create React App / Tooling |
react-error-boundary is like a safety net šŖ ā it catches falls and ensures the user lands safely on a friendly page. It is essential for production apps where reliability matters. You should almost always have this in your production codebase.
react-error-overlay is like a diagnostic tool š ā it opens up the engine to show you exactly which wire is sparking. It is essential for building developer tools or customizing your dev environment, but it is not a replacement for error boundaries in production.
Final Thought: For most application developers, react-error-boundary is the daily driver for handling errors gracefully. react-error-overlay is a specialized tool you likely only touch if you are configuring the development experience itself. Use the boundary to protect your users, and let your dev server handle the overlay for your debugging needs.
Choose react-error-boundary when you need to prevent your application from crashing due to unexpected errors in production. It is the standard choice for implementing graceful degradation, allowing you to show a friendly "Something went wrong" message and optionally retry. Use this for wrapping feature modules, routes, or entire apps where stability and user experience are priorities.
Choose react-error-overlay if you are building custom development tooling or a dev server and need to replicate the Create React App error reporting UI. It is not typically used for production error handling. Select this only if you need to display detailed stack traces and build errors to developers in a browser overlay during the development phase.
react-error-boundary: Reusable React error boundary component. Supports all React renderers (including React DOM and React Native).
# npm
npm install react-error-boundary
# pnpm
pnpm add react-error-boundary
# yarn
yarn add react-error-boundary
Frequently asked questions can be found here.
A reusable React error boundary component. Wrap this component around other React components to "catch" errors and render a fallback UI.
This package is built on top of React error boundaries, so it has all of the advantages and constraints of that API. This means that it can't catch errors during:
ā¹ļø The component provides several ways to render a fallback: fallback, fallbackRender, and FallbackComponent.
Refer to the documentation to determine which is best for your application.
ā¹ļø This is a client component. You can only pass props to it that are serializeable or use it in files that have a "use client"; directive.
None
| Name | Description |
|---|---|
| onError | Optional callback to enable e.g. logging error information to a server.
@param error Value that was thrown; typically an instance of |
| onReset | Optional callback to to be notified when an error boundary is "reset" so React can retry the failed render. |
| resetKeys | When changed, these keys will reset a triggered error boundary. This can be useful when an error condition may be tied to some specific state (that can be uniquely identified by key). See the the documentation for examples of how to use this prop. |
| fallback | Static content to render in place of an error if one is thrown.
|
| FallbackComponent | React component responsible for returning a fallback UI based on a thrown value.
|
| fallbackRender | Render prop function responsible for returning a fallback UI based on a thrown value.
|
ErrorBoundary cannot be used as a JSX componentThis error can be caused by a version mismatch between react and @types/react. To fix this, ensure that both match exactly, e.g.:
If using NPM:
{
...
"overrides": {
"@types/react": "17.0.60"
},
...
}
If using Yarn:
{
...
"resolutions": {
"@types/react": "17.0.60"
},
...
}
This blog post shows more examples of how this package can be used, although it was written for the version 3 API.