UNPKG

@replyke/ui-core-react-js

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

27 lines 858 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = require("react"); function useWidth() { const [width, setWidth] = (0, react_1.useState)(0); const ref = (0, react_1.useRef)(null); (0, react_1.useEffect)(() => { const handleResize = (entries) => { if (entries[0].contentRect) { setWidth(entries[0].contentRect.width); } }; const resizeObserver = new ResizeObserver(handleResize); const currentRef = ref.current; if (currentRef) { resizeObserver.observe(currentRef); } return () => { if (currentRef) { resizeObserver.unobserve(currentRef); } }; }, []); return [width, ref]; } exports.default = useWidth; //# sourceMappingURL=useWidth.js.map