import React, { Component } from 'react'; type State = { hasError: boolean; error: Error | null; }; class ErrorBoundary extends Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: any) { console.error('ErrorBoundary caught an error:', error, errorInfo); } render() { if (this.state.hasError) { return (
{this.state.error?.message || 'An unexpected error occurred'}