saladday1's picture
code: sync from git
2471af3 verified
Raw History Blame
992 Bytes
import { Component, StrictMode, type ReactNode } from "react"
import { createRoot } from "react-dom/client"
import "./index.css"
import App from "./App.tsx"
// Follow the system light/dark setting (shadcn's dark styles key off the .dark class).
const mq = matchMedia("(prefers-color-scheme: dark)")
const apply = () => document.documentElement.classList.toggle("dark", mq.matches)
apply()
mq.addEventListener("change", apply)
// If the page and its data file ever disagree, say so instead of showing a blank page.
class Fallback extends Component<{ children: ReactNode }, { failed: boolean }> {
state = { failed: false }
static getDerivedStateFromError() {
return { failed: true }
}
render() {
return this.state.failed ? <p style={{ padding: 40, fontSize: 18 }}>Something went wrong. Try refreshing the page.</p> : this.props.children
}
}
createRoot(document.getElementById("root")!).render(
<StrictMode>
<Fallback>
<App />
</Fallback>
</StrictMode>,
)