react-error-boundary

Simple reusable React error boundary component

MIT License

Downloads
20.2M
Stars
6.4K
Committers
38

Bot releases are hidden (Show)

react-error-boundary - 4.0.13 Latest Release

Published by bvaughn 8 months ago

Removed references to ESLint config kcd-scripts from package.json

react-error-boundary - 4.0.12

Published by bvaughn 10 months ago

  • Support null fallback prop (#169)
react-error-boundary - 4.0.11

Published by bvaughn about 1 year ago

  • Re-throw original error in the event that no fallback is specified (#160)
  • Improved exported prop types def (#152)
  • Bundle built with Preconstruct (#144, #149, 9b7b15bc29829b2a145c047ef188fecb90c9894e)
react-error-boundary - 4.0.10

Published by bvaughn over 1 year ago

  • Target Safari 12+ compatibility (by removing optional chaining operator and default parameters)
react-error-boundary - 4.0.9

Published by bvaughn over 1 year ago

  • 145: Removed explicit ErrorBoundary.render return type to avoid TypeScript error:

'ErrorBoundary' cannot be used as a JSX component.

react-error-boundary - 4.0.8

Published by bvaughn over 1 year ago

  • 144: Build release bundle with Preconstruct
react-error-boundary - 4.0.7

Published by bvaughn over 1 year ago

*Replaced post-processing "use client" insertion step with a custom Parcel plug-in. This should hopefully produce better source maps.

react-error-boundary - 4.0.6

Published by bvaughn over 1 year ago

  • Removed arrow function syntax to support older versions of Safari
react-error-boundary - 4.0.5

Published by bvaughn over 1 year ago

Move "use client" directive to top of the bundled file.

react-error-boundary - 4.0.4

Published by bvaughn over 1 year ago

README changes only

react-error-boundary -

Published by bvaughn over 1 year ago

  • withErrorBoundary forwards refs
  • Add "use client" directive
react-error-boundary - 4.0.2

Published by bvaughn over 1 year ago

Fix broken TypeScript definitions file (#133, https://github.com/parcel-bundler/parcel/issues/8908)

react-error-boundary - 4.0.1

Published by bvaughn over 1 year ago

  • Render ErrorBoundaryContext around fallback UI as well, so the useErrorBoundary hook could be used within the fallback component to reset the boundary.

For example:

import { useErrorBoundary } from "react-error-boundary";

function ErrorFallback({ error }) {
  const { resetBoundary } = useErrorBoundary();

  return (
    <div role="alert">
      <p>Something went wrong:</p>
      <pre style={{ color: "red" }}>{error.message}</pre>
      <button onClick={resetBoundary}>Try again</button>
    </div>
  );
}

See this demo: https://codesandbox.io/s/nostalgic-browser-e9lpmf

react-error-boundary - 4.0.0

Published by bvaughn over 1 year ago

  • Replace useErrorHandler hook with useErrorBoundary; can be used to trigger an error boundary or dismiss one
  • Merge onReset and onResetKeys props; pass "details" object explaining the cause of the reset

Why did the useErrorHandler hook change?

The old hook had two design flaws, both related to the givenError parameter:

  1. All the hook did was throw this value. This seemed unnecessary, because if a component already has a reference to an error during render, it can just throw the value itself.
  • It would not properly re-throw null or undefined values. (Although an edge case, JavaScript enables throwing any values/types.)

If you were using the givenError functionality– you can now just throw the value directly instead.

// Before
function Greeting() {
  const [name, setName] = React.useState('')
  const {greeting, error} = useGreeting(name)
  useErrorHandler(error)
// After
function Greeting() {
  const [name, setName] = React.useState('')
  const {greeting, error} = useGreeting(name)
  if (error) {
    throw error;
  }

How can I use the new useErrorHandler hook?

Show the nearest error boundary from an event handler

React only handles errors thrown during render or during component lifecycle methods (e.g. effects and did-mount/did-update). Errors thrown in event handlers, or after async code has run, will not be caught.

This hook can be used to pass those errors to the nearest error boundary:

import { useErrorBoundary } from "react-error-boundary";

function Example() {
  const { showBoundary } = useErrorBoundary();

  useEffect(() => {
    fetchGreeting(name).then(
      response => {
        // Set data in state and re-render
      },
      error => {
        // Show error boundary
        showBoundary(error);
      }
    );
  });

  // Render ...
}

Dismiss the nearest error boundary

A fallback component can use this hook to request the nearest error boundary retry the render that original failed.

import { useErrorBoundary } from "react-error-boundary";

function ErrorFallback({ error }) {
  const { resetBoundary } = useErrorBoundary();

  return (
    <div role="alert">
      <p>Something went wrong:</p>
      <pre style={{ color: "red" }}>{error.message}</pre>
      <button onClick={resetBoundary}>Try again</button>
    </div>
  );
}
react-error-boundary - v3.0.2

Published by kentcdodds about 4 years ago

3.0.2 (2020-09-15)

Bug Fixes

  • TS: TypeScript types for onError (#70) (c8272e2)
react-error-boundary - v3.0.1

Published by kentcdodds about 4 years ago

3.0.1 (2020-09-12)

Bug Fixes

  • TS: types for v3 breaking change (#69) (6810c4e)
react-error-boundary - v3.0.0

Published by kentcdodds about 4 years ago

3.0.0 (2020-09-11)

Bug Fixes

BREAKING CHANGES

  • This removes the componentStack in the props given to the FallbackComponent and fallbackRender
react-error-boundary - v2.3.2

Published by kentcdodds about 4 years ago

2.3.2 (2020-09-10)

Bug Fixes

  • switch to getDerivedStateFromError to avoid unnecessary rerender (#67) (463c62e), closes #66
react-error-boundary - v2.3.1

Published by kentcdodds about 4 years ago

2.3.1 (2020-07-23)

Bug Fixes

react-error-boundary - v2.3.0

Published by kentcdodds about 4 years ago

2.3.0 (2020-07-20)

Features

  • useErrorHandler: add new hook for handling errors (#59) (3c93397)