Skip to content

Commit

Permalink
fix up logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pacocoursey committed Aug 18, 2023
1 parent 4ee5ee6 commit 1579445
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/next-themes/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,15 @@ const Theme: React.FC<ThemeProviderProps> = ({

const setTheme = useCallback(
theme => {
setThemeState(prevTheme => {
const currentTheme = prevTheme ?? defaultTheme
const newTheme = typeof theme === 'function' ? theme(currentTheme) : currentTheme

// Save to storage
try {
localStorage.setItem(storageKey, newTheme)
} catch (e) {
// Unsupported
}

return newTheme
})
const newTheme = typeof theme === 'function' ? theme(theme) : theme
setThemeState(newTheme)

// Save to storage
try {
localStorage.setItem(storageKey, newTheme)
} catch (e) {
// Unsupported
}
},
[forcedTheme]
)
Expand Down

0 comments on commit 1579445

Please sign in to comment.