Created
June 18, 2021 23:56
-
-
Save vzhou842/dacf8ff1c41f8c3cd28d474cae3e9dee to your computer and use it in GitHub Desktop.
OS Preference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const darkQuery = window.matchMedia('(prefers-color-scheme: dark)'); | |
if (darkQuery.matches) { | |
console.log('The user prefers dark mode!'); | |
} | |
darkQuery.addListener(e => { | |
console.log(`Preference update: ${e.matches ? 'does' : 'does not'} prefer dark mode`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment