mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
fix theme hook
This commit is contained in:
parent
1828f29cfb
commit
01f0c707dc
@ -5,8 +5,11 @@ export const useTheme = (defaultTheme = 'default') => {
|
||||
const savedTheme = localStorage.getItem('theme')
|
||||
const initialTheme = savedTheme ? (JSON.parse(savedTheme) as string) : defaultTheme
|
||||
if (initialTheme !== 'default') {
|
||||
document.documentElement.setAttribute('data-theme', defaultTheme)
|
||||
document.documentElement.setAttribute('data-theme', initialTheme)
|
||||
localStorage.setItem('theme', JSON.stringify(initialTheme))
|
||||
} else {
|
||||
document.documentElement.removeAttribute('data-theme')
|
||||
localStorage.removeItem('theme')
|
||||
}
|
||||
}, [defaultTheme])
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user