feature/IO-3499-React-19: Move react-grid-gallery to a vendor directory internally, will be removed shortly but for now we keep it

This commit is contained in:
Dave
2026-01-13 17:17:28 -05:00
parent 1764397195
commit 7bdfbfabe9
15 changed files with 615 additions and 17 deletions

View File

@@ -0,0 +1,37 @@
import { useCallback, useRef, useState } from "react";
export function useContainerWidth(defaultContainerWidth) {
const ref = useRef(null);
const observerRef = useRef();
const [containerWidth, setContainerWidth] = useState(defaultContainerWidth);
const containerRef = useCallback((node) => {
observerRef.current?.disconnect();
observerRef.current = undefined;
ref.current = node;
const updateWidth = () => {
if (!ref.current) {
return;
}
let width = ref.current.clientWidth;
try {
width = ref.current.getBoundingClientRect().width;
} catch {
//
}
setContainerWidth(Math.floor(width));
};
updateWidth();
if (node && typeof ResizeObserver !== "undefined") {
observerRef.current = new ResizeObserver(updateWidth);
observerRef.current.observe(node);
}
}, []);
return { containerRef, containerWidth };
}