import React, { Component, type ReactNode } from "react"; interface ErrorBoundaryProps { children: ReactNode; } interface ErrorBoundaryState { hasError: boolean; error: Error | null; } class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false, error: null, }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error, }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error("Uncaught error:", error, errorInfo); } render() { if (this.state.hasError) { return ( <>

Something went wrong.

{this.state.error?.stack}
); } return this.props.children; } } export default ErrorBoundary;