import { Component } from 'react' import type { ErrorInfo, ReactNode } from 'react' interface Props { children: ReactNode fallback?: ReactNode } interface State { hasError: boolean error: Error | null } export class ErrorBoundary extends Component { constructor(props: Props) { super(props) this.state = { hasError: false, error: null } } static getDerivedStateFromError(error: Error): State { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Log error to console in development if (import.meta.env.DEV) { console.error('ErrorBoundary caught an error:', error, errorInfo) } // In production, you could send to error tracking service // Example: Sentry.captureException(error, { contexts: { react: errorInfo } }) } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback } return (

Something went wrong

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

) } return this.props.children } }