import { Component, type ErrorInfo, type ReactNode } from "react"; interface Props { children: ReactNode; viewName: string; } 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): void { console.error("[ErrorBoundary]", this.props.viewName, error, info); } render(): ReactNode { if (this.state.hasError) { return (

{this.props.viewName}

Something went wrong in this view

{this.state.error && (

{this.state.error.message}

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