diff --git a/src/components/Theme/ThemePrivider.tsx b/src/components/Theme/ThemePrivider.tsx index ace0ed9..31c1eee 100644 --- a/src/components/Theme/ThemePrivider.tsx +++ b/src/components/Theme/ThemePrivider.tsx @@ -37,10 +37,7 @@ export function ThemeProvider({ const [theme, setTheme] = useState( () => (localStorage.getItem(storageKey) as ThemeSection) || defaultTheme ); - - useEffect(() => { - localStorage.setItem(storageKey, theme); - }, [theme]); + // const [theme, setTheme] = useState("system"); // 在组件退出前监听系统主题变化,实时切换主题 useEffect(() => { @@ -72,6 +69,7 @@ export function ThemeProvider({ if (activeTheme && activeTheme !== "system") { setTheme(activeTheme); } + localStorage.setItem(storageKey, activeTheme || "system"); }, [activeTheme]); const value = {