Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

react-error-boundary

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-error-boundary

Simple reusable React error boundary component

Source
npmnpm
Version
6.0.1
Version published
Weekly downloads
8.6M
0.63%
Maintainers
2
Weekly downloads
 
Created
Source

react-error-boundary

Reusable React error boundary component. Supports all React renderers (including React DOM and React Native).

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Getting started

# npm
npm install react-error-boundary

# pnpm
pnpm add react-error-boundary

# yarn
yarn add react-error-boundary

API

ErrorBoundary

A reusable React error boundary component. Wrap this component around other React components to "catch" errors and render a fallback UI.

ℹ️ 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.

Required props

None

Optional props

NameDescription
onError

Optional callback to enable e.g. logging error information to a server. @param error Error that was thrown @param info React "component stack" identifying where the error was thrown

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.

<ErrorBoundary fallback={<div class="text-red">Something went wrong</div>} />
FallbackComponent

React component responsible for returning a fallback UI based on a thrown value.

<ErrorBoundary FallbackComponent={Fallback} />
fallbackRender

Render prop function responsible for returning a fallback UI based on a thrown value.

<ErrorBoundary fallbackRender={({ error, resetErrorBoundary }) => <div>...</div>} />

FAQ

ErrorBoundary cannot be used as a JSX component

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

Keywords

react

FAQs

Package last updated on 29 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts