useResizeObserver
Commons
stable
Wraps the native ResizeObserver API with a reactive template ref. Returns a resizeRef to attach to any element and a readonly contentRect that updates on every resize. Automatically disconnects the observer on component unmount. Supports both content-box (default) and border-box measurement.
API
Signature
Full TypeScript signature sourced from the composable file.
Consumed interfaces
IResizeState
API
Parameters
Input parameters accepted by this composable.
- callbackResizeObserverCallback
- Optional raw ResizeObserver callback. Receives the full entries array and the observer instance. Called on every resize event before contentRect is updated.
- box'content' | 'border''content'
- Which box model dimension to capture. "content" uses entries[0].contentRect; "border" calls getBoundingClientRect() on the element for border-box dimensions including padding and border.
API
Return values
Properties and methods exposed by the composable return object.
- resizeRef
- Assign this ref to the element you want to observe: <div :ref="resizeRef">. Watching the ref automatically connects/disconnects the observer.
- contentRect
- Reactive dimensions of the observed element. undefined until the first resize event fires. Provides width, height, top, left, right, bottom.
Usage
Examples
Ready-to-paste usage snippets.
Track element dimensions reactively
Custom callback + border-box