From f45e0be4de6acfe60ddfd94d1078beb634ecdb2c Mon Sep 17 00:00:00 2001 From: pqcqaq <905739777@qq.com> Date: Tue, 16 Jul 2024 22:53:38 +0800 Subject: [PATCH] Theme bug fixed --- src/components/Theme/ThemePrivider.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 = {