UNPKG

tdesign-react

Version:
55 lines (51 loc) 1.89 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import { _ as _slicedToArray } from '../../_chunks/dep-48805ab8.js'; import { useMemo, useState, useEffect } from 'react'; import { o as observe } from '../../_chunks/dep-4450afc0.js'; import '../../_chunks/dep-026a4c6b.js'; function useLazyLoad(containerRef, childRef, params) { var tRowHeight = useMemo(function () { return Math.max(params.rowHeight || 48, 48); }, [params.rowHeight]); var _useState = useState(function () { return params.rowIndex === -1; }), _useState2 = _slicedToArray(_useState, 2), isInit = _useState2[0], setIsInit = _useState2[1]; var hasLazyLoadHolder = useMemo(function () { return (params === null || params === void 0 ? void 0 : params.type) === "lazy" && !isInit; }, [isInit, params === null || params === void 0 ? void 0 : params.type]); var requestAnimationFrame = (typeof window === "undefined" ? false : window.requestAnimationFrame) || function (cb) { return setTimeout(cb, 16.6); }; var init = function init() { if (!isInit) { requestAnimationFrame(function () { setIsInit(true); }); } }; useEffect(function () { if ((params === null || params === void 0 ? void 0 : params.type) !== "lazy") return; var timer = setTimeout(function () { var bufferSize = Math.max(10, params.bufferSize || 10); var height = tRowHeight * bufferSize; childRef && observe(childRef.current, containerRef, init, height); clearTimeout(timer); }); return function () { clearTimeout(timer); }; }, [childRef, containerRef, params.bufferSize, params === null || params === void 0 ? void 0 : params.type, tRowHeight]); return { hasLazyLoadHolder: hasLazyLoadHolder, tRowHeight: tRowHeight }; } export { useLazyLoad as default }; //# sourceMappingURL=useLazyLoad.js.map