import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { App } from './App';
import './styles/globals.css';
class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ hasError: boolean; error: Error | null; showStack: boolean }
> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { hasError: false, error: null, showStack: false };
}
static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('[ErrorBoundary]', error, errorInfo.componentStack);
}
render() {
if (this.state.hasError) {
return (
Something went wrong
{this.state.error?.message}
this.setState({ hasError: false, error: null })}
style={{
padding: '8px 24px',
backgroundColor: '#7c6cf6',
color: 'white',
border: 'none',
borderRadius: '8px',
cursor: 'pointer',
fontSize: '14px',
fontFamily: "'DM Sans', sans-serif",
}}
>
Try Again
window.location.reload()}
style={{
padding: '8px 24px',
backgroundColor: 'transparent',
color: '#a0a0aa',
border: '1px solid rgba(255,255,255,0.1)',
borderRadius: '8px',
cursor: 'pointer',
fontSize: '14px',
fontFamily: "'DM Sans', sans-serif",
}}
>
Reload Page
{this.state.error?.stack && (
this.setState({ showStack: (e.target as HTMLDetailsElement).open })}
style={{ maxWidth: '600px', width: '100%', marginTop: '8px' }}
>
Error details
{this.state.error.stack}
)}
);
}
return this.props.children;
}
}
const root = document.getElementById('root');
if (!root) throw new Error('Root element not found');
ReactDOM.createRoot(root).render(