Watches for size changes of an element using ResizeObserver.
ResizeObserver
The element type.
The callback to execute on resize.
A ref object to attach to the target element.
This hook returns a ref to attach to the element. The callback receives the ResizeObserverEntry array. The callback can optionally return a cleanup function.
ResizeObserverEntry
const ref = useResizeObserver((entries) => { for (const entry of entries) { console.log(entry.contentRect); }});return <div ref={ref} />; Copy
const ref = useResizeObserver((entries) => { for (const entry of entries) { console.log(entry.contentRect); }});return <div ref={ref} />;
Watches for size changes of an element using
ResizeObserver.