Last active
May 28, 2025 07:10
-
-
Save ZacharyBear/1c44237db76a7a3c02a6c45608613497 to your computer and use it in GitHub Desktop.
Revisions
-
ZacharyBear revised this gist
May 28, 2025 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,8 +15,6 @@ const useDark = () => { subscribe, () => match.matches ) return dark } -
ZacharyBear created this gist
May 28, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import { useMemo, useSyncExternalStore } from 'React' const useDark = () => { const match = useMemo(() => window.matchMedia('(prefers-color-scheme: dark)'), []) // Handlers const subscribe = (cb: () => void) => { match.addEventListener('change', cb) return () => match.removeEventListener('change', cb) } // Syncs const dark = useSyncExternalStore( subscribe, () => match.matches ) useEffect(() => console.log('dark is', dark), [dark]) return dark }