UNPKG

@activecollab/components

Version:

ActiveCollab Components

41 lines 997 B
import _extends from "@babel/runtime/helpers/esm/extends"; import { useState, useEffect } from "react"; const useRectHook = ref => { const _useState = useState({ x: 0, y: 0, top: 0, left: 0, bottom: 0, right: 0, width: 0, height: 0 }), size = _useState[0], setSize = _useState[1]; useEffect(() => { const listener = () => { if (ref && ref.current) { const rect = ref.current.getBoundingClientRect(); setSize({ x: rect.x, y: rect.y, top: rect.top, left: rect.left, bottom: rect.bottom, right: rect.right, width: rect.width, height: rect.height }); } }; listener(); window.addEventListener("resize", listener); return () => { window.removeEventListener("resize", listener); }; }, [ref]); return _extends({}, size); }; export default useRectHook; //# sourceMappingURL=useRectHook.js.map