UNPKG

@winglet/react-utils

Version:

React utility library providing custom hooks, higher-order components (HOCs), and utility functions to enhance React application development with improved reusability and functionality

35 lines (34 loc) 1.2 kB
import { Component, type ErrorInfo, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; } /** * Error boundary component that catches JavaScript errors during component rendering and displays fallback UI. * Prevents the entire application from crashing when errors occur in child components. * @example * <ErrorBoundary fallback={<CustomErrorUI />}> * <MyComponent /> * </ErrorBoundary> */ export declare class ErrorBoundary extends Component<Props, State> { constructor(props: Props); /** * Called when an error occurs in a child component and returns the new state. * @param error - The error object that was thrown * @returns The updated state object */ static getDerivedStateFromError(error: Error): State; /** * Called after an error occurs in a child component, allowing for side effects like logging. * @param error - The error object that was thrown * @param errorInfo - Additional information about the error */ componentDidCatch(error: Error, errorInfo: ErrorInfo): void; render(): ReactNode; } export {};