diff --git a/playgrounds/app/src/components/theme-switcher.tsx b/playgrounds/app/src/components/theme-switcher.tsx index 0b86ce2..6f17fbb 100644 --- a/playgrounds/app/src/components/theme-switcher.tsx +++ b/playgrounds/app/src/components/theme-switcher.tsx @@ -2,22 +2,17 @@ import { createSignal, createEffect } from 'solid-js' import { makePersisted } from '@solid-primitives/storage' export function createThemeSwitcher() { - const [isDarkMode, setIsDarkMode] = makePersisted(createSignal(false), { + const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)') + const [isDarkMode, setIsDarkMode] = makePersisted(createSignal(prefersDarkScheme.matches), { name: 'isDarkMode', }) createEffect(() => { - const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)') - if (isDarkMode()) { document.body.classList.add('dark') } else { document.body.classList.remove('dark') } - - if (isDarkMode() === null) { - setIsDarkMode(prefersDarkScheme.matches) - } }) const toggleDarkMode = () => {