import { Component, type ErrorInfo, type ReactNode } from 'react'; import { Button } from './Button'; interface Props { children: ReactNode; /** reset key — when it changes, the boundary clears its error */ resetKey?: string | number; } interface State { error: Error | null; } /** Catches render errors so one broken screen never white-screens the whole app. */ export class ErrorBoundary extends Component { override state: State = { error: null }; static getDerivedStateFromError(error: Error): State { return { error }; } override componentDidCatch(error: Error, info: ErrorInfo): void { console.error('Render error caught by boundary:', error, info.componentStack); } override componentDidUpdate(prev: Props): void { if (prev.resetKey !== this.props.resetKey && this.state.error) { this.setState({ error: null }); } } override render(): ReactNode { if (this.state.error) { return (

Something went wrong

This screen hit an error. Your data is safe — try again or reload.

            {this.state.error.message}
          
); } return this.props.children; } }