import React, { Component, ReactNode } from 'react'; import Typography from './ui/Typography'; import { Button } from './ui/Button'; interface ErrorBoundaryProps { children: ReactNode; } interface ErrorBoundaryState { hasError: boolean; error?: Error; } /** * Error boundary component to catch and handle React errors gracefully. * Prevents the entire app from crashing when a component throws an error. */ export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { } render() { if (this.state.hasError) { return (
Oops! Something went wrong We encountered an unexpected error. Please try refreshing the page. {this.state.error && (
{this.state.error.message}
)}
); } return this.props.children; } }