import { Component, type ErrorInfo, type ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { error: Error | null; } export default class ErrorBoundary extends Component { state: State = { error: null }; static getDerivedStateFromError(error: Error): State { return { error }; } componentDidCatch(error: Error, info: ErrorInfo) { console.error('UI error:', error, info); } render() { if (this.state.error) { return ( this.props.fallback ?? (

Something failed to render

{this.state.error.message}

) ); } return this.props.children; } }