Skip to content
Entangle UI v0.13.0

useResizeObserver

useResizeObserver<T>(ref, callback, options?): void

Defined in: src/hooks/useResizeObserver/useResizeObserver.ts:39

Observe size changes on an element. SSR-safe; cleans up on unmount.

The callback is wrapped with useEventCallback so consumers do not have to memoize it — the underlying observer never re-subscribes when the callback identity changes.

The hook re-checks ref.current on every render so it picks up nodes that mount later (e.g. through conditional rendering). When the observed node has not changed the only cost is a single identity comparison.

T extends HTMLElement

RefObject<T | null>

(entry) => void

UseResizeObserverOptions

void

const ref = useRef<HTMLDivElement>(null);
useResizeObserver(ref, entry => {
console.log(entry.contentRect.width);
});
return <div ref={ref} />;