Created
January 10, 2024 16:53
-
-
Save SitaGomes/de1a86611e8f2fba7ce698fbeb4e18e7 to your computer and use it in GitHub Desktop.
A hook that returns the current view port of the page
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
export const useGetViewPort = () => { | |
const [width, setWidth] = useState(window.innerWidth); | |
useEffect(() => { | |
const handleWindowResize = () => setWidth(window.innerWidth); | |
window.addEventListener("resize", handleWindowResize); | |
return () => window.removeEventListener("resize", handleWindowResize); | |
}, []); | |
// return the width so we can use it in our components | |
return width; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment