Created
January 16, 2023 09:10
-
-
Save kp-gists/6cfb18a70172b34a4bcc7a462257c406 to your computer and use it in GitHub Desktop.
useWindowSize w useOnScreen
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
| import { useState } from "react" | |
| import useEventListener from "../13-useEventListener/useEventListener" | |
| export default function useWindowSize() { | |
| const [windowSize, setWindowSize] = useState({ | |
| width: window.innerWidth, | |
| height: window.innerHeight, | |
| }) | |
| useEventListener("resize", () => { | |
| setWindowSize({ width: window.innerWidth, height: window.innerHeight }) | |
| }) | |
| return windowSize | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment