useMeasure
Measures the dimensions and box insets of a DOM element via a callback ref and ResizeObserver.
Loading preview...
The useMeasure hook returns a [ref, rect] tuple that observes a DOM element with ResizeObserver and provides its width, height, and box insets (top, left, right, bottom, x, y), automatically re-subscribing when conditionally rendered elements mount or unmount.
Installation
Usage
API Reference
UseMeasureOptions
Configuration options for the observed CSS box model.
Property
Specification
box?uniondefault:'content-box'
CSS box model to observe
Full Signature
enabled?uniondefault:true
Whether measurement observation is active
Full Signature
MeasureRect
Measured dimensions and box coordinates returned as the second tuple element.
Property
Specification
xrequirednumber
Horizontal offset of the measured box in pixels
yrequirednumber
Vertical offset of the measured box in pixels
widthrequirednumber
Width of the measured box in pixels
heightrequirednumber
Height of the measured box in pixels
toprequirednumber
Top inset of the measured box in pixels
rightrequirednumber
Right edge coordinate (
left + width) in pixelsbottomrequirednumber
Bottom edge coordinate (
top + height) in pixelsleftrequirednumber
Left inset of the measured box in pixels