// components/ErrorBoundary/index.tsx import React, { Component, ReactNode } from "react"; import { Result, Button } from "antd-mobile"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error?: Error; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: any) { console.error("ErrorBoundary caught an error:", error, errorInfo); } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (
); } return this.props.children; } } export default ErrorBoundary;