import React, { Component, ErrorInfo, ReactNode } from 'react'; interface Props { children: ReactNode; fallback?: ReactNode; } 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, errorInfo: ErrorInfo): void { console.error('Erro capturado pelo ErrorBoundary:', error, errorInfo); } handleReset = (): void => { this.setState({ hasError: false, error: null }); }; render(): ReactNode { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

Algo deu errado

Ocorreu um erro inesperado. Por favor, tente novamente.

{this.state.error && (

{this.state.error.message}

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