import React from 'react'; import { Component, ErrorInfo, ReactNode } from 'react'; import Button from '../ui/Button'; import { withTranslation, WithTranslation } from 'react-i18next'; interface Props extends WithTranslation { fallback?: ReactNode; children: ReactNode; } interface State { hasError: boolean; } class ErrorBoundary extends Component { public state: State = { hasError: false, }; public static getDerivedStateFromError(_: Error): State { // Update state so the next render will show the fallback UI. return { hasError: true }; } public componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); } public render() { if (this.state.hasError) { return this.props.fallback ? ( this.props.fallback ) : (

{this.props.t('error.generic')}

); } return this.props.children; } } export default withTranslation(['common'])(ErrorBoundary);