Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System query causes initial mode to ignore initialState value #54

Open
abbott opened this issue Jun 25, 2020 · 1 comment
Open

System query causes initial mode to ignore initialState value #54

abbott opened this issue Jun 25, 2020 · 1 comment

Comments

@abbott
Copy link

abbott commented Jun 25, 2020

System query causes initial mode to ignore initialState value — is this a feature or a bug?

If a site prioritizes a particular mode by setting initialState then system preference would be ignored. The user would have to manually change the site preference, otherwise if initialState is null, then the system preference is used.

@tom-sherman
Copy link

tom-sherman commented Mar 29, 2021

Hi, if I'm understanding you correctly you can solve this using the matchMedia API. Here's how I did it:

https://github.com/NorfolkDev/norfolkdevelopers-website/blob/39c988376c38976f9eaa2dfac3638c6fd938ec14/src/components/DarkModeToggle.tsx#L7-L10

const darkMode = useDarkMode(
  window.matchMedia('(prefers-color-scheme: dark)').matches
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants