import { useRef } from 'react' ; import useWindowSize from 'react-use/lib/useWindowSize' ; export function useRefDimensions ( ) { const ref = useRef < HTMLDivElement > ( null ) ; const windowHeight = useWindowSize ( ) . height ; if ( ! ref . current ) { return { ref , width : 0 , height : 0 } ; } const { top , width } = ref . current . getBoundingClientRect ( ) ; const height = windowHeight - top ; return { ref , width , height } ; }