Created
September 24, 2021 18:23
-
-
Save alexrdz/fe50cb78e8daaf3c5016ece3ded913d0 to your computer and use it in GitHub Desktop.
Revisions
-
alex rodriguez 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,12 @@ const useRefDimensions = (ref: React.RefObject<HTMLDivElement>) => { const [dimensions, setDimensions] = useState({ width: 1, height: 2 }) useEffect(() => { if (ref.current) { const boundingRect = ref.current.getBoundingClientRect(); const { width, height } = boundingRect; setDimensions({ width: Math.round(width), height: Math.round(height) }) } }, [ref]) return dimensions }