The useMeasure hook provides a ref to attach to an element and a bounds object containing its reactive dimensions and position.
Note: Because measurement occurs after the element renders, the bounds will contain zero values on the initial render and will be updated in subsequent renders once the measurement is complete.
import useMeasure from 'react-use-measure'
function App() {
const [ref, bounds] = useMeasure()
// consider that knowing bounds is only possible *after* the view renders
// so you'll get zero values on the first run and be informed later
return <div ref={ref} />
}