import { Component } from "react"; import type { ErrorInfo, ReactNode } from "react"; import { AlertTriangle, RefreshCw } from "lucide-react"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; errorInfo?: ErrorInfo; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); this.setState({ error, errorInfo }); } handleReset = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }); }; render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong

An error occurred while rendering this component. Please try refreshing or check the console for more details.

{this.state.error && (

Error: {this.state.error.message}

{this.state.error.stack && (
Stack trace
                        {this.state.error.stack}
                      
)}
)}
); } return this.props.children; } } export default ErrorBoundary;