import React from 'react'; import { Text, Button, Stack } from '@mantine/core'; interface ErrorBoundaryState { hasError: boolean; error?: Error; } interface ErrorBoundaryProps { children: React.ReactNode; fallback?: React.ComponentType<{error?: Error; retry: () => void}>; } export default class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('ErrorBoundary caught an error:', error, errorInfo); } retry = () => { this.setState({ hasError: false, error: undefined }); }; render() { if (this.state.hasError) { if (this.props.fallback) { const Fallback = this.props.fallback; return ; } return ( Something went wrong {process.env.NODE_ENV === 'development' && this.state.error && ( {this.state.error.message} )} ); } return this.props.children; } }