"use client"; import { Component, ReactNode } from "react"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; } export class ErrorBoundary extends Component { state: State = { hasError: false }; static getDerivedStateFromError(): State { return { hasError: true }; } render() { if (this.state.hasError) { return this.props.fallback || (
页面加载出错
); } return this.props.children; } }