import { Component, type ErrorInfo, type ReactNode } from 'react' type ScreenErrorBoundaryProps = { children: ReactNode } type ScreenErrorBoundaryState = { error: Error | null } export class ScreenErrorBoundary extends Component { state: ScreenErrorBoundaryState = { error: null } static getDerivedStateFromError(error: Error): ScreenErrorBoundaryState { return { error } } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Screen rendering failed.', error, errorInfo.componentStack) } private retry = () => { this.setState({ error: null }) } render() { if (this.state.error) { return (

This screen could not be displayed

{this.state.error.message || 'An unexpected error occurred.'}

) } return this.props.children } }