Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
aeolianeth committed Sep 19, 2024
1 parent 5c828da commit d601388
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/contexts/Theme/useJuiceTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const userPrefersDarkMode = (): boolean => {

export const getInitialThemeOption = () => {
if (typeof window === 'undefined') {
return false
return
}

const storedThemeOption = localStorage?.getItem(THEME_STORAGE_KEY)
Expand All @@ -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) {
Expand All @@ -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)
}, [])

Expand Down

0 comments on commit d601388

Please sign in to comment.