import React, { Component, ErrorInfo, ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { public state: State = { hasError: false, error: null, }; public static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Log error to console and backend console.error('Uncaught error:', error, errorInfo); // Forward to backend log if (window.service?.native?.log) { void window.service.native.log('error', `React Error Boundary caught: ${error.message}`, { error: { name: error.name, message: error.message, stack: error.stack, }, componentStack: errorInfo.componentStack, }); } } public render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Something went wrong.

{this.state.error?.toString()}
{this.state.error?.stack}
); } return this.props.children; } }