const useRefDimensions = (ref: React.RefObject) => { 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 }