import { Component, type ReactNode } from "react"; export class ErrorBoundary extends Component<{ children: ReactNode }, { err: Error | null }> { state: { err: Error | null } = { err: null }; static getDerivedStateFromError(err: Error) { return { err }; } render() { if (this.state.err) { return (

页面出错了

{String(this.state.err)}

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