Created
September 17, 2019 11:00
-
-
Save builat/4764df3ded03c91795003063b07b3dd1 to your computer and use it in GitHub Desktop.
Hook for getting rect bounds
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
| type BoundsT = { | |
| height: number | |
| width: number | |
| x: number | |
| y: number | |
| top: number | |
| bottom: number | |
| } | |
| function useBounds<T>(): [LegacyRef<T>, BoundsT] { | |
| const ref = useRef(null) | |
| const [bounds, setBounds] = useState() | |
| useLayoutEffect(() => { | |
| setBounds(ref.current.getBoundingClientRect()) | |
| }, [ref]) | |
| return [ref, bounds] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment