import { Component, type ErrorInfo, type ReactNode } from "react"; import { motion } from "framer-motion"; interface Props { children: ReactNode; fallback?: ReactNode; onError?: (error: Error, info: ErrorInfo) => void; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, info: ErrorInfo) { const { onError } = this.props; if (onError) { onError(error, info); } } handleReset = () => { this.setState({ hasError: false, error: null }); }; render() { const { hasError, error } = this.state; const { fallback, children } = this.props; if (hasError) { if (fallback) return fallback; /* eslint-disable i18next/no-literal-string */ return (

Something went wrong

{error?.message || "An unexpected error occurred. Please try again."}

); /* eslint-enable i18next/no-literal-string */ } return children; } }