Created
June 12, 2026 11:14
-
-
Save mg901/6cf996444a45f9ad10d0e4e02cb0c15d to your computer and use it in GitHub Desktop.
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 characters
| function useWindowSize() { | |
| const width = useSyncExternalStore( | |
| subscribe, | |
| () => window.innerWidth, | |
| () => 0, | |
| ); | |
| const height = useSyncExternalStore( | |
| subscribe, | |
| () => window.innerHeight, | |
| () => 0, | |
| ); | |
| return { | |
| width, | |
| height, | |
| }; | |
| } | |
| function subscribe(listener) { | |
| window.addEventListener("resize", listener); | |
| return () => { | |
| window.removeEventListener("resize", listener); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment