useResizeObserver
Observes the size of an element.
Usage
useResizeObserver
listens for the size of an element, it uses ResizeObserver under the hood.
import { useState } from "react";
import { useResizeObserver } from "swash/utils/useResizeObserver";
function Example({ onChange }) {
const [width, setWidth] = useState(null);
const containerRef = useResizeObserver((entry) => {
setWidth(entry.contentRect.width);
});
return <div ref={containerRef}>{/* ... */}</div>;
}