import { Component, type ErrorInfo, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } export class ErrorBoundary extends Component { state: State = { hasError: false, error: null, errorInfo: null, }; static getDerivedStateFromError(error: Error): Partial { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { this.setState({ error, errorInfo }); console.error('ErrorBoundary:', error, errorInfo); } render() { if (this.state.hasError && this.state.error) { if (this.props.fallback) return this.props.fallback; return (
⚠️

Произошла ошибка

Приложение столкнулось с неожиданной ошибкой

{import.meta.env.DEV && (
{this.state.error.toString()}
)}
); } return this.props.children; } }