ilokesto

ErrorBoundary

ErrorBoundary catches render errors in descendants and renders fallback instead. Pair with Mount (which handles async errors) to cover both synchronous render errors and asynchronous factory errors.

import { ErrorBoundary } from '@ilokesto/utilinent';

<ErrorBoundary fallback={({ error, reset }) => <button onClick={reset}>Retry</button>}>
  <RiskyWidget />
</ErrorBoundary>

Props

PropTypeDescription
childrenReactNodeThe subtree to guard.
fallbackReactNode | ({ error, reset }) => ReactNodeRendered when a descendant throws.
onError(error, info) => voidCalled when an error is caught.
resetKeysreadonly unknown[]When these values change, the boundary resets.

A render-prop fallback receives the caught error and a reset callback that clears the error state.

On this page