useResizeObserver
API
import useResizeObserver from '@restart/hooks/useResizeObserver'
useResizeObserver
<TElement>(element: TElement | null | undefined) => Rect | nullEfficiently observe size changes on an element. Depends on the
ResizeObserver
api, and polyfills are needed in older browsers.const [ref, attachRef] = useCallbackRef(null);const rect = useResizeObserver(ref);return (<div ref={attachRef}>{JSON.stringify(rect)}</div>)Parameters
element
TElement | null | undefinedThe DOM element to observe
Return Value Rect | null