Skip to content

Instantly share code, notes, and snippets.

@nirnejak
Created May 23, 2022 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirnejak/8db4c6b600f1744990f3e8b41a08a449 to your computer and use it in GitHub Desktop.
Save nirnejak/8db4c6b600f1744990f3e8b41a08a449 to your computer and use it in GitHub Desktop.
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
handleDarkmode(darkModeMediaQuery)
function handleDarkmode(e) {
const darkModeOn = e.matches; // true if dark mode is enabled
if (darkModeOn) {
// TODO: Set Dark Theme
} else {
// TODO: Set Light Theme
}
}
darkModeMediaQuery.addListener(handleDarkmode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment