import { Component, type ErrorInfo, type ReactNode } from 'react'; import { AlertTriangle, RefreshCw } from 'lucide-react'; interface Props { children: ReactNode; fallbackTitle?: string; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { public state: 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); } public handleReset = () => { this.setState({ hasError: false, error: null }); }; public render() { if (this.state.hasError) { return (

{this.props.fallbackTitle || 'Something went wrong in this section'}

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

); } return this.props.children; } }