import { useState } from 'react'; import useEffect from './useIsomorphicEffect'; var targetMap = new WeakMap(); var resizeObserver; function getResizeObserver() { // eslint-disable-next-line no-return-assign return resizeObserver = resizeObserver || new window.ResizeObserver(function (entries) { entries.forEach(function (entry) { var handler = targetMap.get(entry.target); if (handler) handler(entry.contentRect); }); }); } /** * Efficiently observe size changes on an element. Depends on the `ResizeObserver` api, * and polyfills are needed in older browsers. * * ```ts * const [ref, attachRef] = useCallbackRef(null); * * const rect = useResizeObserver(ref); * * return ( *