import { Component, type ReactNode } from "react"; interface Props { children: ReactNode; fallback?: ReactNode; } interface State { hasError: boolean; error: Error | null; } export class ErrorBoundary extends Component { state: State = { hasError: false, error: null }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } render() { if (this.state.hasError) { if (this.props.fallback) return this.props.fallback; return (

Something went wrong

{this.state.error?.message || "An unexpected error occurred."}

); } return this.props.children; } }