Returns the size of an element and its position relative to the viewport.
import { useMeasure } from 'use-haki';
const App = () => {
const [rect, rectRef] = useMeasure();
return <pre ref={rectRef}>{JSON.stringify(rect, null, 2)}</pre>;
};
const [rect, rectRef] = useMeasure();
- rect - DOMRect object with properties like
width
,height
,x
,y
... - rectRef - element that you want to grab
- rectRef
- rect