import React from 'react'; import { View, Text, ScrollView, Platform } from 'react-native'; import { Button } from './ui/button'; interface Props { children: React.ReactNode; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error) { console.error('ErrorBoundary caught an error:', error); } private resetError = () => { this.setState({ hasError: false, error: null }); }; private restartApp = () => { if (Platform.OS === 'web') { window.location.reload(); } else { // For native platforms, just reset the error state // The app will re-mount components this.resetError(); } }; render() { if (this.state.hasError) { return ( Something went wrong {this.state.error?.message} {__DEV__ && ( {this.state.error?.stack} )} ); } return this.props.children; } }