"use client";
import * as React from "react";
import styles from "./error-boundary.module.css";
/**
* Represents the configurable props for the {@link ErrorBoundary} component.
*
* @remarks
* Accepts child content plus an optional fallback renderer and error callback for
* recovery-oriented error handling in React client trees.
*/
interface ErrorBoundaryProps {
/**
* Content rendered when no error has been captured.
*/
children: React.ReactNode;
/**
* Custom fallback UI or render function invoked with the current error and reset action.
*/
fallback?: React.ReactNode | ((error: Error, reset: () => void) => React.ReactNode);
/**
* Callback invoked after an error has been captured.
*/
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
}
/**
* Represents the tracked state for the {@link ErrorBoundary} component.
*
* @remarks
* Stores the most recent rendering error so the boundary can swap to fallback UI and
* later clear that error when `reset()` is invoked.
*/
interface ErrorBoundaryState {
/**
* The latest captured error, or `null` when the subtree is healthy.
*/
error: Error | null;
}
/**
* Catches JavaScript errors in descendant client components and renders fallback UI.
*
* @remarks
* **Rendering Context**: Client component.
*
* React currently requires class components for error boundaries. This implementation
* captures render-time and lifecycle errors, not asynchronous event handler exceptions,
* and exposes a `reset()` pathway so callers can retry the failed subtree.
*
* @example
* ```tsx
* (
*