import React from 'react'; import { logError } from '../utils/errorLogger'; class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error) { return { hasError: true, error }; } componentDidCatch(error, errorInfo) { // Extract component stack for richer context const componentInfo = { component: errorInfo?.componentStack || null, props: this.props, }; logError(error, componentInfo); } handleRetry = () => { this.setState({ hasError: false, error: null }); }; renderDefaultFallback() { return (
An unexpected error occurred. You can try again.