This commit is contained in:
root
2026-06-07 18:06:52 +08:00
parent 9de2465793
commit a1daa040ef
33 changed files with 1917 additions and 439 deletions

View File

@@ -34,16 +34,9 @@ function getInitialTheme(): Theme {
}
export function ThemeProvider({ children }: { children: ReactNode }) {
const [theme, setThemeState] = useState<Theme>("light");
const [mounted, setMounted] = useState(false);
const [theme, setThemeState] = useState<Theme>(() => getInitialTheme());
useEffect(() => {
setThemeState(getInitialTheme());
setMounted(true);
}, []);
useEffect(() => {
if (!mounted) return;
const root = document.documentElement;
if (theme === "dark") {
root.classList.add("dark");
@@ -55,7 +48,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
} catch {
/* ignore */
}
}, [theme, mounted]);
}, [theme]);
const setTheme = useCallback((newTheme: Theme) => {
setThemeState(newTheme);