Skip to content

Releases: bvaughn/react-error-boundary

4.0.8

29 May 20:59
Compare
Choose a tag to compare
  • 144: Build release bundle with Preconstruct

4.0.7

27 May 20:33
Compare
Choose a tag to compare

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

4.0.6

27 May 19:02
Compare
Choose a tag to compare
  • Removed arrow function syntax to support older versions of Safari

4.0.5

27 May 18:57
Compare
Choose a tag to compare

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

4.0.4

17 Apr 19:06
Compare
Choose a tag to compare

README changes only

4.0.3

12 Apr 13:20
Compare
Choose a tag to compare
  • withErrorBoundary forwards refs
  • Add "use client" directive

4.0.2

23 Mar 14:07
Compare
Choose a tag to compare

Fix broken TypeScript definitions file (#133, parcel-bundler/parcel#8908)

4.0.1

22 Mar 14:15
Compare
Choose a tag to compare
  • 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

4.0.0

22 Mar 00:38
66cc1a2
Compare
Choose a tag to compare
  • 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>
  );
}

v3.1.4

29 Oct 05:15
a0a370c
Compare
Choose a tag to compare

3.1.4 (2021-10-29)

Bug Fixes