# @stefanprobst/next-error-boundary

> Minimal React `ErrorBoundary` component. The fallback component can access the thrown error with the `useError` hook, and reset the error state by calling `onReset`.

Latest version **3.0.2** (published 2021-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @stefanprobst/next-error-boundary
pnpm add @stefanprobst/next-error-boundary
yarn add @stefanprobst/next-error-boundary
bun add @stefanprobst/next-error-boundary
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2021-11-08 |
| First published | 2020-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.17 |
| Dependencies | 1 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | stefanprobst |

## Links

- npm: https://www.npmjs.com/package/@stefanprobst/next-error-boundary
- Repository: https://github.com/stefanprobst/next-error-boundary
- Homepage: https://github.com/stefanprobst/next-error-boundary#readme
- Issues: https://github.com/stefanprobst/next-error-boundary/issues
- npm.io page: https://npm.io/package/@stefanprobst/next-error-boundary

## Dependencies (1)

- [@stefanprobst/assert](https://npm.io/package/@stefanprobst/assert.md) ^1.0.1

## Recent versions

- 3.0.2 (latest) — 2021-11-08
- 3.0.2-legacy (legacy) — 2022-01-20
- 3.0.0 — 2021-10-27
- 2.0.0 — 2021-10-27
- 1.0.8 — 2021-07-11
- 1.0.7 — 2021-01-08
- 1.0.6 — 2021-01-07
- 1.0.5 — 2020-10-29
- 1.0.4 — 2020-10-27
- 1.0.3 — 2020-10-27
- 1.0.1 — 2020-10-27
- 1.0.0 — 2020-09-10

## README

# next-error-boundary

Minimal React `ErrorBoundary` component. The fallback component can access the thrown error with the
`useError` hook, and reset the error state by calling `onReset`.

## Example

```tsx
import { useRouter } from 'next/router'
import ErrorBoundary, { useError } from '@stefanprobst/next-error-boundary'

function CustomErrorPage() {
  const { error, onReset } = useError()
  return (
    <section role="alert">
      <p>An unexpected error has occurred: {error.message}.</p>
      <button onClick={onReset}>Reset</button>
    </section>
  )
}

export default function Page() {
  const { router } = useRouter()
  return (
    <ErrorBoundary
      fallback={<CustomErrorPage />}
      onError={(error, errorInfo) => console.error(error, errorInfo)}
      onReset={() => resetStuffThatThrewError()}
      /**
       * Reset the error component when the route changes.
       */
      key={router.asPath}
    >
      <main>
        <h1>Hello World</h1>
      </main>
    </ErrorBoundary>
  )
}
```

---
_Source: https://npm.io/package/@stefanprobst/next-error-boundary · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
