import React, { Component, ErrorInfo, ReactNode } from 'react'; import { AlertTriangle, RefreshCw } from 'lucide-react'; interface Props { children?: ReactNode; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundary extends Component { public state: State = { hasError: false }; public readonly props: Readonly; constructor(props: Props) { super(props); this.props = props; } public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); } public render() { if (this.state.hasError) { return (

出错了

抱歉,系统遇到了一些问题。
{this.state.error?.message || 'Unknown Error'}

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