Gives the dimensions of any element
liveMeasure?: Bool
: Adds scroll and resize events to always have the latest dimensions, default istrue
.delay?: Number
: delay for debounce calculation, default is250
.initialDimensions?: Object
: Default dimensions before the calculation. Default is{}
.effectDependencies?: Array
: List of effects to re-call useLayoutEffect, default is[]
.
ref: Ref
: Give this ref to the element needing the calculationdimensions: Object
: All of the element's dimensionsnode: Node
: The Element
import { useDimensions } from "react-recipes";
function App() {
const [wrapperRef, dimensions] = useDimensions();
return (
<div ref={wrapperRef}>
height: {dimensions.height}
width: {dimensions.width}
</div>
);
}