npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-error-boundary

v6.1.2

Published

Simple reusable React error boundary component

Readme

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

[!NOTE] Projects using framework or runtimes that don't support ES Modules should use version 5 of this library.

Getting started

# npm
npm install react-error-boundary

# pnpm
pnpm add react-error-boundary

# yarn
yarn add react-error-boundary

Documentation

Read the react-error-boundary docs for examples, API reference, and troubleshooting. The docs also include a frequently asked questions guide.

Quick start

Wrap an ErrorBoundary around the part of the tree where you want to show a fallback UI if rendering fails. Your fallback can call resetErrorBoundary to clear the error and retry rendering:

"use client";

import { ErrorBoundary, getErrorMessage } from "react-error-boundary";

export default function App() {
  return (
    <ErrorBoundary
      fallbackRender={({ error, resetErrorBoundary }) => (
        <div role="alert">
          <p>Something went wrong:</p>
          <pre>{getErrorMessage(error)}</pre>
          <button onClick={resetErrorBoundary}>Try again</button>
        </div>
      )}
      onError={(error, info) => {
        // Log the error to your error reporting service
      }}
      onReset={() => {
        // Reset any state that may have caused the error
      }}
    >
      {/* Components protected by this boundary */}
    </ErrorBoundary>
  );
}

What errors are caught?

This package is built on top of React error boundaries, so it follows React's rules for what errors are caught.

Error boundaries catch errors thrown while rendering the tree below them.

Error boundaries do not catch errors thrown during:

  • Server side rendering
  • Event handlers
  • Errors thrown in the error boundary itself
  • Async code that runs after rendering, like setTimeout callbacks or unresolved promises

Async errors

For async errors:

  • Use useErrorBoundary to pass caught errors to the nearest boundary.
  • In React 19, useTransition Actions can be an alternative: errors thrown from a function passed to the returned startTransition function are caught by the nearest boundary.
"use client";

import { useTransition } from "react";
import { ErrorBoundary } from "react-error-boundary";

function UserProfileContainer({ username }: { username: string }) {
  return (
    <ErrorBoundary fallback={<p>Could not load profile</p>}>
      <UserProfile username={username} />
    </ErrorBoundary>
  );
}

function UserProfile({ username }: { username: string }) {
  const [isPending, startTransition] = useTransition();

  function loadProfile() {
    startTransition(async () => {
      await fetchUserProfile(username);
    });
  }

  return (
    <button disabled={isPending} onClick={loadProfile}>
      {isPending ? "Loading..." : "Load profile"}
    </button>
  );
}

API

ErrorBoundary

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

Catches errors thrown while rendering the tree below it.

Does not catch errors thrown during:

  • Server side rendering
  • Event handlers
  • Errors thrown in the error boundary itself
  • Async code that runs after rendering, like setTimeout callbacks or unresolved promises

Async errors:

  • Use useErrorBoundary to pass caught errors to the nearest boundary
  • In React 19, errors thrown from a function passed to the startTransition function returned by useTransition are caught by the nearest boundary

ℹ️ 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 serializable or use it in files that have a "use client"; directive.

Required props

None

Optional props

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.