Patterns
Error Boundary
React error boundary with a friendly retry fallback.
A React error boundary that catches render errors in its subtree and shows a friendly fallback — an icon, message, and a "Try again" button that resets the boundary. Override the copy with labels, supply a fully custom fallback, or hook into onError for logging.
Import
tsx1 line
import { ErrorBoundary } from "@yuhuanowo/yunui/patterns";Basic
Wrap any subtree. While no error is thrown, it renders its children transparently.
ErrorBoundary
This content is protected by an error boundary.
Custom labels
Pass labels to localize the fallback's title, message, and retry button.
tsx6 linesScroll horizontally
<ErrorBoundary labels={{ title: "Something broke", message: "Please try again.", retry: "Reload" }} onError={(error, info) => logToService(error, info)}> <Dashboard /></ErrorBoundary>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| fallback | ReactNode | — | |
| labels | ErrorBoundaryLabels | — | Override the default English copy. |
| onError | ((error: Error, info: ErrorInfo) => void) | — | Notified when an error is caught (e.g. for logging). |