import { Component, ErrorInfo, ReactNode } from "react"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(_: Error): State { return { hasError: true }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error("ErrorBoundary caught an error:", error, errorInfo); } render() { if (this.state.hasError) { return ( this.props.children || (

Error

) ); } return this.props.children; } } export default ErrorBoundary;