メインコンテンツまでスキップ

ErrorBoundary

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

Catches render errors thrown by its children and shows an error-variant Callout in their place, so one broken widget doesn't take the whole frame down with it.

Import​

import { ErrorBoundary } from "~lib/feedback/error-boundary";

Props​

NameTypeRequiredDefaultDescription
childrenReactNodeYesN/AContent to render and monitor for errors
titlestringNo"Something went wrong"Heading shown by the default fallback Callout
fallback(props: FallbackProps) => ReactNodeNoN/ARenders in place of the default Callout when an error is caught
onError(error: unknown, info: ErrorInfo) => voidNoN/ACalled when a child throws
onReset() => voidNoN/ACalled when the boundary resets, either via resetKeys or a fallback's resetErrorBoundary()
resetKeysunknown[]NoN/AWhen any value changes, the boundary clears the error and re-renders children

Examples​

Default​

StorybookでDefaultを開く

Custom Title​

StorybookでCustom Titleを開く

No Error​

StorybookでNo Errorを開く

Custom Fallback​

StorybookでCustom Fallbackを開く

See Also​

  • Callout - Message boxes, including the error variant used by the default fallback
  • EmptyState - No-data placeholder