A React hook that allows you to use a ResizeObserver to measure an element's size.
yarn add use-resize-observer
# or
npm install --save use-resize-observer
import React from "react";
import useResizeObserver from "use-resize-observer";
const App = () => {
const [ref, width, height] = useResizeObserver();
return (
<div ref={ref}>
Size: {width}x{height}
</div>
);
};
- Uses resize-observer-polyfill internally, which falls back to the native ResizeObserver, if available.
MIT