Created
June 19, 2021 00:03
-
-
Save vzhou842/ebce1c42d10c865197b0ae489c7085f4 to your computer and use it in GitHub Desktop.
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)'); | |
// Your Toggle component will need to register here to get updates. | |
window.__themeListeners = []; | |
darkQuery.addListener(e => { | |
window.__setPreferredTheme(e.matches ? 'dark' : 'light'); | |
window.__themeListeners.forEach(l => l()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment