Skip to Content
ComponentsErrorBoundary

Error Boundary

The Error Boundary component provides you with error handling and fallback UI for your application.

Live Examples

Live Example
☀️
Copy
View Code
import { ErrorBoundary } from '@jarllyng/nostromo' function BrokenComponent() { throw new Error('Something went wrong!') return null } export default function ErrorBoundaryExample() { return ( <ErrorBoundary ...

Import

import { ErrorBoundary } from "@jarllyng/nostromo"; // or import { ErrorBoundary } from "@jarllyng/nostromo/error-boundary";

Usage

import { ErrorBoundary } from "@jarllyng/nostromo"; export default function Example() { return ( <ErrorBoundary fallback={({ error, resetError }) => ( <div> <h2>Something went wrong!</h2> <p>{error?.message}</p> <button onClick={resetError}>Try again</button> </div> )} > <YourComponent /> </ErrorBoundary> ); }

Code Examples

import { ErrorBoundary } from "@jarllyng/nostromo"; export default function ErrorBoundaryExample() { return ( <ErrorBoundary fallback={<div>Something went wrong!</div>}> <YourComponent /> </ErrorBoundary> ); }

Props

PropTypeDefaultRequiredDescription
fallbackReact.ComponentType<{ error: Error | undefined; resetError: () => void }> | React.ReactNodeundefinedNoFallback UI component or element to show when error occurs
onError(error: Error, errorInfo: React.ErrorInfo) => voidundefinedNoCallback function called when an error is caught
childrenReact.ReactNode-YesChild components to wrap with error boundary
Last updated on