-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
28 lines (26 loc) · 805 Bytes
/
app.tsx
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
import { useCallback, useEffect, useMemo } from "react";
import { RouterProvider } from "react-router-dom";
import { router } from "./router.tsx";
const [htmlContainer] = document.getElementsByTagName("html");
export const App = () => {
const setTheme = useCallback(() => {
const theme = localStorage.getItem("shell:style");
if (
theme === "dark" ||
theme === "auto" && matchMedia("(prefers-color-scheme: dark)").matches
) {
htmlContainer.className = "pf-v5-theme-dark";
} else {
htmlContainer.className = "";
}
}, []);
useEffect(() => {
setTheme();
addEventListener("storage", (event) => {
if (event.key === "shell:style") {
setTheme();
}
});
}, []);
return useMemo(() => <RouterProvider router={router} />, []);
};