npm install use-bounding-rect
A tiny React hook to access DOM Rect of an element dynamically.
import { useBoundingRect } from "use-bounding-rect";
function Wrapper() {
let ref = useRef(null);
let rect = useBoundingRect(ref);
return (
<div className="wrapper" ref={ref}>
{rect != null ? <Content width={rect.width} height={rect.height} /> : null}
</div>
);
}