import React, { Component, ErrorInfo, ReactNode } from "react"; interface Props { children: ReactNode; fallback?: (error: Error, retry: () => void) => ReactNode; } interface State { hasError: boolean; error: Error | null; } /** * Error Boundary component to catch React errors * Displays a user-friendly error message instead of crashing */ export class ErrorBoundary extends Component { public constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); } private handleRetry = () => { this.setState({ hasError: false, error: null }); }; public render() { if (this.state.hasError) { if (this.props.fallback && this.state.error) { return this.props.fallback(this.state.error, this.handleRetry); } return (

Oops! Something went wrong

{this.state.error?.message || "An unexpected error occurred"}

Error details
                {this.state.error?.stack}
              
); } return this.props.children; } }