import { Component, ErrorInfo, ReactNode } from 'react'; export interface IErrorBoundary { children: ReactNode; fallback: ReactNode; } interface State { hasError: boolean; } export class ErrorBoundary extends Component { public state: State = { hasError: false, }; public static getDerivedStateFromError(_: Error): State { return { hasError: true }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); } public render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; else { return null; } } return this.props.children; } }