import React, { Component, ErrorInfo, ReactNode } from 'react'; import { AlertTriangle } from 'lucide-react'; interface Props { children: ReactNode; fallback?: ReactNode; componentName?: string; } interface State { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; } class ErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null, errorInfo: null, }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error, errorInfo: null, }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('ErrorBoundary caught an error:', error, errorInfo); this.setState({ error, errorInfo, }); } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

{this.props.componentName ? `Error en ${this.props.componentName}` : 'Error de Renderizado'}

Este componente encontró un error y no pudo renderizarse correctamente. El resto del dashboard sigue funcionando normalmente.

Ver detalles técnicos

Error:

{this.state.error?.toString()}

{this.state.errorInfo && ( <>

Stack:

                        {this.state.errorInfo.componentStack}
                      
)}
); } return this.props.children; } } export default ErrorBoundary;