Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
|
@@ -3,8 +3,39 @@ import ReactDOM from 'react-dom/client'
|
|
| 3 |
import App from './cointube'
|
| 4 |
import './index.css'
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
ReactDOM.createRoot(document.getElementById('root')).render(
|
| 7 |
<React.StrictMode>
|
| 8 |
-
<
|
|
|
|
|
|
|
| 9 |
</React.StrictMode>,
|
| 10 |
)
|
|
|
|
| 3 |
import App from './cointube'
|
| 4 |
import './index.css'
|
| 5 |
|
| 6 |
+
// Trampa de errores global
|
| 7 |
+
class ErrorBoundary extends React.Component {
|
| 8 |
+
constructor(props) {
|
| 9 |
+
super(props);
|
| 10 |
+
this.state = { hasError: false, error: null };
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
static getDerivedStateFromError(error) {
|
| 14 |
+
return { hasError: true, error };
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
componentDidCatch(error, errorInfo) {
|
| 18 |
+
console.error("Error atrapado:", error, errorInfo);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
render() {
|
| 22 |
+
if (this.state.hasError) {
|
| 23 |
+
return (
|
| 24 |
+
<div style={{ padding: '20px', color: 'red', backgroundColor: '#ffebee' }}>
|
| 25 |
+
<h1>⚠️ Algo salió mal</h1>
|
| 26 |
+
<pre>{this.state.error?.toString()}</pre>
|
| 27 |
+
<p>Abre la consola (F12) para más detalles.</p>
|
| 28 |
+
</div>
|
| 29 |
+
);
|
| 30 |
+
}
|
| 31 |
+
return this.props.children;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
ReactDOM.createRoot(document.getElementById('root')).render(
|
| 36 |
<React.StrictMode>
|
| 37 |
+
<ErrorBoundary>
|
| 38 |
+
<App />
|
| 39 |
+
</ErrorBoundary>
|
| 40 |
</React.StrictMode>,
|
| 41 |
)
|