Use system theme for initial dark mode setting
This commit is contained in:
parent
808e4d302a
commit
ee569ada7f
@ -14,6 +14,12 @@ export const DarkModeProvider = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [isDark, setIsDark] = React.useState(true);
|
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 (
|
return (
|
||||||
<DarkModeContext.Provider
|
<DarkModeContext.Provider
|
||||||
value={{ isDark, toggleDark: () => setIsDark((d) => !d) }}
|
value={{ isDark, toggleDark: () => setIsDark((d) => !d) }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user