linkmore-design
Version:
🌈 🚀lm组件库。🚀
49 lines (48 loc) • 2.22 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["children", "pref"];
import React, { useRef, useMemo, useEffect } from 'react';
import { useStore } from "./context";
import useForkRef from "../hooks/useForkRef";
var VirtualRow = /*#__PURE__*/React.memo(function (_ref, ref) {
var children = _ref.children,
pref = _ref.pref,
resetProps = _objectWithoutProperties(_ref, _excluded);
var _useStore = useStore(),
state = _useStore.state,
dispatch = _useStore.dispatch;
var rowHeight = state.rowHeight,
totalLen = state.totalLen;
var trRef = useRef(null);
// 列长度
var columnsLen = useMemo(function () {
var _children$length;
return (_children$length = children === null || children === void 0 ? void 0 : children.length) !== null && _children$length !== void 0 ? _children$length : 0;
}, [children]);
useEffect(function () {
if (state.columnsLen !== columnsLen) {
dispatch({
type: 'changeColumnsLen',
columnsLen: columnsLen !== null && columnsLen !== void 0 ? columnsLen : 0
});
}
}, [columnsLen, dispatch, state.columnsLen]);
useEffect(function () {
var initHeight = function initHeight(tempRef) {
var _tempRef$current;
if (tempRef !== null && tempRef !== void 0 && (_tempRef$current = tempRef.current) !== null && _tempRef$current !== void 0 && _tempRef$current.offsetHeight && !rowHeight && totalLen) {
var _tempRef$current$offs, _tempRef$current2;
var tempRowHeight = (_tempRef$current$offs = tempRef === null || tempRef === void 0 ? void 0 : (_tempRef$current2 = tempRef.current) === null || _tempRef$current2 === void 0 ? void 0 : _tempRef$current2.offsetHeight) !== null && _tempRef$current$offs !== void 0 ? _tempRef$current$offs : 0;
dispatch({
type: 'initHeight',
rowHeight: tempRowHeight
});
}
};
initHeight(trRef);
}, [trRef, dispatch, rowHeight, totalLen, ref]);
return /*#__PURE__*/React.createElement("tr", _extends({}, resetProps, {
ref: useForkRef(pref, trRef)
}), children);
});
export default VirtualRow;