import { Component, type ReactNode } from "react"; import { withTranslation, type WithTranslation } from "react-i18next"; type ErrorBoundaryProps = { children: ReactNode; } & WithTranslation; type ErrorBoundaryState = { hasError: boolean; message: string; }; class ErrorBoundaryComponent extends Component { state: ErrorBoundaryState = { hasError: false, message: "", }; static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, message: error.message || "Unknown error", }; } componentDidCatch(error: Error) { console.error(error); } render() { const { t } = this.props; if (this.state.hasError) { return (

{t('pageRenderFailed')}

{this.state.message}

); } return this.props.children; } } export const ErrorBoundary = withTranslation()(ErrorBoundaryComponent);