import { Component, ErrorInfo, ReactNode } from 'react'; interface ErrorBoundaryState { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } interface ErrorBoundaryProps { children: ReactNode; fallback?: ReactNode; } export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Error caught by ErrorBoundary:', error, errorInfo); this.setState({ error, errorInfo, }); } handleReset = () => { this.setState({ hasError: false, error: null, errorInfo: null, }); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong

An unexpected error occurred. The error has been reported.

Error details
Message:

{this.state.error?.message}

{this.state.error?.stack && (
Stack trace:
                        {this.state.error.stack}
                      
)}
); } return this.props.children; } }