From d601388e16a3f6b2fa3a5462fb0221db62be93f4 Mon Sep 17 00:00:00 2001 From: aeolian <94939382+aeolianeth@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:04:45 +1000 Subject: [PATCH] fix types --- src/contexts/Theme/useJuiceTheme.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/contexts/Theme/useJuiceTheme.ts b/src/contexts/Theme/useJuiceTheme.ts index fb91878614..c7307f5e3b 100644 --- a/src/contexts/Theme/useJuiceTheme.ts +++ b/src/contexts/Theme/useJuiceTheme.ts @@ -15,7 +15,7 @@ const userPrefersDarkMode = (): boolean => { export const getInitialThemeOption = () => { if (typeof window === 'undefined') { - return false + return } const storedThemeOption = localStorage?.getItem(THEME_STORAGE_KEY) @@ -26,9 +26,9 @@ export const getInitialThemeOption = () => { return userPrefersDarkMode() ? ThemeOption.dark : ThemeOption.light } -export const syncTheme = (themeOption: ThemeOption) => { - if (typeof document === 'undefined') { - return false +export const syncTheme = (themeOption: ThemeOption | undefined) => { + if (!themeOption || typeof document === 'undefined') { + return } if (themeOption === ThemeOption.dark) { @@ -51,7 +51,11 @@ export function useJuiceTheme(): ThemeContextType { // Load the theme from local storage on initial load useEffect(() => { - const initialThemeOption = getInitialThemeOption(THEME_STORAGE_KEY) + const initialThemeOption = getInitialThemeOption() + if (!initialThemeOption) { + return + } + setCurrentThemeOption(initialThemeOption) }, [])