Use system theme for initial dark mode setting

This commit is contained in:
Nilay Majorwar 2022-01-22 22:48:33 +05:30
parent 808e4d302a
commit ee569ada7f

View File

@ -14,6 +14,12 @@ export const DarkModeProvider = ({
}) => {
const [isDark, setIsDark] = React.useState(true);
// Set dark theme according to system preference
React.useEffect(() => {
if (window.matchMedia("(prefers-color-scheme: light)").matches)
setIsDark(false);
}, []);
return (
<DarkModeContext.Provider
value={{ isDark, toggleDark: () => setIsDark((d) => !d) }}