fn
useResizeObserver
v0.0.15testeddemoReports changes to the dimensions of an element via `ResizeObserver`. Accepts a single target or an array of (reactive) targets. The observer is recreated only when the resolved elements change, and can be paused/resumed.
Examples
ts
useResizeObserver(el, ([entry]) => {
console.log(entry.contentRect.width);
});ts
const { pause, resume } = useResizeObserver([el1, el2], (entries) => {
// react to multiple targets
}, { box: 'border-box' });Demo
Loading demo…
Signature
ts
export function useResizeObserver(
target: MaybeComputedElementRef | MaybeComputedElementRef[],
callback: ResizeObserverCallback,
options: UseResizeObserverOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | any | Element(s) to observe |
callback | ResizeObserverCallback | Invoked with the observer entries |
options? | UseResizeObserverOptions | Options |
Returns
UseResizeObserverReturn`isSupported`, `isActive`, `pause`, `resume`, and `stop`