'use client'; import { Component, ReactNode } from 'react'; import { trackError } from '@/lib/analytics'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; } export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error) { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('Error caught by boundary:', error, errorInfo); trackError('react_error', error.message, true); } render() { if (this.state.hasError) { return this.props.fallback || (

出错了

抱歉,页面出现了问题。请刷新页面重试。

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