import React, { Component, ReactNode } from 'react'; interface Props { children: ReactNode; onError?: (error: Error) => void; } interface State { hasError: boolean; error: Error | null; } export class AsyncErrorBoundary extends Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error) { console.error('AsyncErrorBoundary caught an error:', error); this.props.onError?.(error); } retry = () => { this.setState({ hasError: false, error: null }); }; render() { if (this.state.hasError) { return (

Failed to load data

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

); } return this.props.children; } }