'use client'; import { Component, type ReactNode } from 'react'; type Props = { children: ReactNode; fallback?: ReactNode; }; type State = { hasError: boolean; error: Error | null; }; export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: React.ErrorInfo) { console.error('[ErrorBoundary]', error, info.componentStack); } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

页面出现异常

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