-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.tsx
More file actions
62 lines (53 loc) · 1.69 KB
/
index.tsx
File metadata and controls
62 lines (53 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
/* -------------------------------------------------------------------------- */
/* Error Boundary */
/* -------------------------------------------------------------------------- */
class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ hasError: boolean; error: Error | null }
> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error("ErrorBoundary caught an error:", error, errorInfo);
}
render() {
if (this.state.hasError) {
return (
<div className="h-screen flex items-center justify-center bg-black text-white">
<div className="text-center">
<h1 className="text-2xl font-bold mb-2">
Something went wrong
</h1>
<p className="text-gray-400">
Please refresh the page.
</p>
</div>
</div>
);
}
return this.props.children;
}
}
/* -------------------------------------------------------------------------- */
/* Mount app ONCE */
/* -------------------------------------------------------------------------- */
const rootElement = document.getElementById("root");
if (!rootElement) {
throw new Error("Could not find root element to mount to");
}
ReactDOM.createRoot(rootElement).render(
<React.StrictMode>
<ErrorBoundary>
<App />
</ErrorBoundary>
</React.StrictMode>
);