`react-error-boundary`: Reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component. Supports all React renderers (including React DOM and React Native).
### If you like this project, đ [become a sponsor](https://github.com/sponsors/bvaughn/) or â [buy me a coffee](http://givebrian.coffee/)
> [!NOTE]
> Projects using frameworks or runtimes that don't support ES Modules should use version 5 of this library.
## Getting started
```sh
# 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](https://react-error-boundary-lib.vercel.app/) for examples, API reference, and troubleshooting. The docs also include a [frequently asked questions guide](https://react-error-boundary-lib.vercel.app/common-questions).
## 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:
```tsx
"use client";
import { ErrorBoundary, getErrorMessage } from "react-error-boundary";
export default function App() {
return (
Something went wrong:
{getErrorMessage(error)}
| 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 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 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.
|