Created
July 14, 2021 23:00
-
-
Save marcovincit/6dfaabbd1938571f4cad4934e534b565 to your computer and use it in GitHub Desktop.
Revisions
-
marcovincit created this gist
Jul 14, 2021 .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,21 @@ import { useEffect, useState } from "react"; export default function useWindowSize() { const [windowWidth, setWindowWidth] = useState(0); const [windowHeight, setWindowHeight] = useState(0); useEffect(() => { function updateSize() { setWindowWidth(window.innerWidth); setWindowHeight(window.innerHeight); } window.addEventListener("resize", updateSize); updateSize(); return () => window.removeEventListener("resize", updateSize); }, []); return { windowWidth, windowHeight }; }