import React, { Component } from 'react'; class ErrorBoundary extends Component { constructor(props) { super(props); this.state = { hasError: false, error: null, errorInfo: null }; } static getDerivedStateFromError(error) { return { hasError: true }; } componentDidCatch(error, errorInfo) { this.setState({ error: error, errorInfo: errorInfo }); // Log error to analytics service in production if (process.env.NODE_ENV === 'production') { console.error('Error caught by boundary:', error, errorInfo); } } render() { if (this.state.hasError) { return (

Something went wrong

We're sorry - an unexpected error occurred. Please try refreshing the page.

{process.env.NODE_ENV === 'development' && (
Error details

{this.state.error && this.state.error.toString()}

{this.state.errorInfo?.componentStack}
)}
); } return this.props.children; } } export default ErrorBoundary;