fix theme hook

This commit is contained in:
Anton Tranelis 2025-06-19 13:32:19 +02:00
parent 1828f29cfb
commit 01f0c707dc

View File

@ -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])
}