Simple but effective. Thanks for sharing
Just to enrich the conversation I want to add that another consideration is that if you are using styled-components a dark theme might be accomplished with something in a similar way, for example:
styled-components
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches const lightTheme = { color: 'black', backgroundColor: 'white', }; const darkTheme = { color: 'white', backgroundColor: 'black', }; // ... render() { return( <ThemeProvider theme={prefersDark ? darkTheme : lightTheme} > </ThemeProvider> ); }
When I change to dark theme in Firefox then this line: window.matchMedia("(prefers-color-scheme: dark)").matches still returns false.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Simple but effective. Thanks for sharing
Just to enrich the conversation I want to add that another consideration is that if you are using
styled-components
a dark theme might be accomplished with something in a similar way, for example:When I change to dark theme in Firefox then this line:
window.matchMedia("(prefers-color-scheme: dark)").matches
still returns false.