donavon / use-dark-mode

A custom React Hook to help you implement a "dark mode" component.
MIT License
1.29k stars 98 forks source link

Is there way not to use system color prefer state as default value? #60

Open jothachil opened 4 years ago

jothachil commented 4 years ago

if system prefer value is in dark mode the react app by default will start in dark mode is there any way the default value is always light mode?

djD-REK commented 4 years ago

According to the docs it looks like you could pass initialState as false. If that's getting overridden by the system default then maybe you could call a useEffect() hook with an empty array [] as the second parameter so it only runs once in page load. In that you'd do dark mode.disable to force it.

Best regards, Derek

Derek R. Austin, PT, DPT, MS, BCTMB, LMT, CSCS

Read my blog on Medium: https://medium.com/@DoctorDerek

Join me on LinkedIn: https://www.linkedin.com/in/derek-austin/

On Tue, Sep 22, 2020, 12:10 PM John Thachil notifications@github.com wrote:

if system prefer value is in dark mode the react app by default will start in dark mode is there any way the default value is always light mode?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/donavon/use-dark-mode/issues/60, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMV42QV4CWJ52RHUF4BFIBLSHDD6JANCNFSM4RV64JYQ .

jothachil commented 4 years ago

@djD-REK Got it. But the edge case here is even if the the default value is false and if system theme preference is set in auto. During the time system switch from light mode -> dark mode the react app will get changed to dark mode. Anyway I can enforce the change in theme is only by user action in the app.

oririechman commented 3 years ago

I just modified the matchMedia of the window object to null as a work around

window.matchMedia = null;
const { value } = useDarkMode(true);