diff --git a/src/components/Meta/Favicon.tsx b/src/components/Meta/Favicon.tsx index 19a2694..384fd65 100644 --- a/src/components/Meta/Favicon.tsx +++ b/src/components/Meta/Favicon.tsx @@ -10,7 +10,7 @@ const MetaFavicons = () => { - + ) } diff --git a/src/components/ThemeSwitch/index.tsx b/src/components/ThemeSwitch/index.tsx index 39c0f42..ad23d15 100644 --- a/src/components/ThemeSwitch/index.tsx +++ b/src/components/ThemeSwitch/index.tsx @@ -12,11 +12,6 @@ export default function ThemeSwitch() { - {/* */} () const [themeColor, setThemeColor] = useState() const toggleDarkMode = useCallback(() => { setDarkMode(!darkMode) }, [darkMode]) + // + // Init + // + useEffect(() => { + const prefersDark = getDarkMode() + setDarkMode(prefersDark) + }, []) + // // Do things when darkMode changes // useEffect(() => { - const bodyClassList = document.body.classList + const bodyClassList = document.querySelector('body').classList bodyClassList.toggle('dark') bodyClassList.toggle('light') setThemeColor(darkMode === true ? '#1d2224' : '#e7eef4')