Created
September 24, 2021 15:35
-
-
Save eriksachse/b596d6be54007f04bc2c8fee792a8fde to your computer and use it in GitHub Desktop.
Revisions
-
eriksachse revised this gist
Sep 24, 2021 . 1 changed file with 0 additions and 5 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 @@ -1,5 +0,0 @@ -
eriksachse revised this gist
Sep 24, 2021 . 1 changed file with 5 additions and 0 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 @@ -0,0 +1,5 @@ import useWindowDimensions from "./hooks/useWindowDimensions"; export default function Masonry(props) { const { width, height } = useWindowDimensions(); } -
eriksachse revised this gist
Sep 24, 2021 . 1 changed file with 0 additions and 5 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 @@ -1,5 +0,0 @@ -
eriksachse created this gist
Sep 24, 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,5 @@ import useWindowDimensions from "./hooks/useWindowDimensions"; export default function Masonry(props) { const { width, height } = useWindowDimensions(); } 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,31 @@ import { useState, useEffect } from "react"; export default function useWindowDimensions() { const hasWindow = typeof window !== "undefined"; function getWindowDimensions() { const width = hasWindow ? window.innerWidth : null; const height = hasWindow ? window.innerHeight : null; return { width, height, }; } const [windowDimensions, setWindowDimensions] = useState( getWindowDimensions() ); useEffect(() => { if (hasWindow) { function handleResize() { setWindowDimensions(getWindowDimensions()); } window.addEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize); } }, [hasWindow]); return windowDimensions; }