import React, { Component, type ReactNode } from 'react'; interface Props { children: ReactNode; } interface State { hasError: boolean; error: Error | null; } export default class ErrorBoundary extends Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error) { return { hasError: true, error }; } componentDidCatch(error: Error, info: React.ErrorInfo) { // 生产环境错误日志记录入口 // TODO: 集成遥测服务后将错误上报 console.error('QRGen ErrorBoundary 捕获错误:', error.message, info.componentStack); } render() { if (this.state.hasError) { return (

应用发生错误

{this.state.error?.message}

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