React hook that watches for changes in element size using ResizeObserver and reports updates forcing component to render. There are two hooks in this package
- useResizeObserver(handlerFn, elementRef) -- Calls
handlerFn()
when element size changed with instance of DOMRectReadOnly. - useElementSize(elementRef, reinitInEffect = true) -- Returns element size or null if
elementRef.current
does not contain reference to HTMLElement.reinitInEffect
forces immediate re-render to apply element sizes, expected to have a valid reference at the time of re-render.
Example on codesandbox.io.