import { Component, ErrorInfo, ReactNode } from 'react'; import { Button, StyleSheet, View } from 'react-native'; import { ThemedText } from './ThemedText'; import { ThemedView } from './ThemedView'; type ErrorBoundaryProps = { children: ReactNode; }; type ErrorBoundaryState = { hasError: boolean; error?: Error; }; export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('ErrorBoundary caught an error', error, errorInfo); } handleRetry = () => { this.setState({ hasError: false, error: undefined }); }; render() { if (this.state.hasError) { return ( Something went wrong {this.state.error?.message ?? 'An unexpected error occurred.'}