koval-ui
Version:
React components collection with minimalistic design. Supports theming, layout, and input validation.
25 lines (24 loc) • 932 B
JavaScript
"use client";
import { useRef as l, useState as m, useMemo as i, useEffect as s } from "react";
function d(t) {
const r = l(0), [e, o] = m(), u = i(
() => ({ width: e == null ? void 0 : e.inlineSize, height: e == null ? void 0 : e.blockSize }),
[e == null ? void 0 : e.blockSize, e == null ? void 0 : e.inlineSize]
), n = i(
() => typeof window < "u" ? new ResizeObserver((a) => {
const c = a[0];
c && (cancelAnimationFrame(r.current), r.current = requestAnimationFrame(() => {
t.current && o(c.borderBoxSize[0]);
}));
}) : null,
[]
// eslint-disable-line react-hooks/exhaustive-deps
);
return s(() => (t.current && (n == null || n.observe(t.current, { box: "border-box" })), () => {
n == null || n.disconnect(), r.current && cancelAnimationFrame(r.current);
}), [t.current]), u;
}
export {
d as useResizeObserver
};
//# sourceMappingURL=useResizeObserverNew.js.map