From d8014699d574d72524dc7d64c16371b369d8459d Mon Sep 17 00:00:00 2001 From: chrismclarke Date: Wed, 6 Mar 2024 14:34:20 -0800 Subject: [PATCH] fix: theme select --- frontend/lib/themeProvider.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/lib/themeProvider.tsx b/frontend/lib/themeProvider.tsx index 59d3d148..0abdeeda 100644 --- a/frontend/lib/themeProvider.tsx +++ b/frontend/lib/themeProvider.tsx @@ -24,6 +24,11 @@ export default function ThemeProvider(props: CustomProps) { else setTheme("light"); } + function handleThemeChange(theme: string) { + document.documentElement.setAttribute("data-theme", theme); + setTheme(theme); + } + useEffect(() => { const storedTheme = localStorage.getItem("daisyUI-theme"); if (storedTheme) { @@ -32,7 +37,7 @@ export default function ThemeProvider(props: CustomProps) { if ((temp === "light" || temp === "dark") && props.useSystem === true) { systemCheck(); } else { - setTheme(temp); + handleThemeChange(temp); } } else if (props.useSystem) { systemCheck(); @@ -46,17 +51,13 @@ export default function ThemeProvider(props: CustomProps) { const updateTheme = (newTheme: string) => { if (newTheme) { - setTheme(newTheme); + handleThemeChange(newTheme); } }; return ( - {loading ? null : ( -
- {props.children} -
- )} + {loading ? null : <>{props.children}}
); }