use dark theme by default

This commit is contained in:
Qing
2022-10-20 21:06:53 +08:00
parent 2ecccb6290
commit c6268d52b2

View File

@@ -4,21 +4,12 @@ import { SunIcon, MoonIcon } from '@heroicons/react/outline'
export const themeState = atom({
key: 'themeState',
default: 'light',
default: 'dark',
})
export const ThemeChanger = () => {
const [theme, setTheme] = useRecoilState(themeState)
useEffect(() => {
const darkThemeMq = window.matchMedia('(prefers-color-scheme: dark)')
if (darkThemeMq.matches) {
setTheme('dark')
} else {
setTheme('light')
}
}, [setTheme])
const themeSwitchHandler = () => {
const newTheme = theme === 'light' ? 'dark' : 'light'
setTheme(newTheme)