Skip to content

Commit 6921195

Browse files
committed
slight performance tweak on defaultSize
1 parent 783f7d7 commit 6921195

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// don't force es6 functions to include space before paren
2323
"space-before-function-paren": 0,
2424
"prettier/prettier": "error",
25-
"no-debugger": true,
25+
"no-debugger": 2,
2626
"semi": "off"
2727
}
2828
}

src/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function Row<T>({
209209
const onExpanderClick = useCallback(() => {
210210
dispatch({ type: "updateExpanded", key: generateKeyFromRow(row, index) });
211211
expandedCalledRef.current = true;
212-
}, [dispatch, row, index, generateKeyFromRow, expandedCalledRef]);
212+
}, [dispatch, row, index, generateKeyFromRow]);
213213

214214
const resetHeight = useCallback(() => {
215215
if (!rowRef.current || !pixelWidths.length) {

src/Table.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ const ListComponent = forwardRef(function (
6161
const treeRef = useRef(new NumberTree());
6262
const tableRef = useRef<HTMLDivElement>(null);
6363
const cacheRef = useRef<{ [index: number]: number }>({});
64+
const defaultSizeRef = useRef(rowHeight || DEFAULT_ROW_HEIGHT);
6465
const { dispatch, uuid, columns, minColumnWidth, fixedWidth, remainingCols, pixelWidths } =
6566
useContext(TableContext);
6667
const [useRowWidth, setUseRowWidth] = useState(true);
67-
const [defaultSize, setDefaultSize] = useState(rowHeight || DEFAULT_ROW_HEIGHT);
6868

6969
// constants
7070
const hasFooter = useMemo(() => {
@@ -107,17 +107,18 @@ const ListComponent = forwardRef(function (
107107
const row = typeof queryParam === "number" ? findRowByUuidAndKey(uuid, key) : queryParam;
108108

109109
if (!row) {
110-
return cacheRef.current[dataIndex] || defaultSize;
110+
return cacheRef.current[dataIndex] || defaultSizeRef.current;
111111
}
112112

113113
const arr = [...row.children].slice(rowHeight ? 1 : 0) as HTMLElement[];
114-
const res = arr.reduce((pv, c) => pv + c.offsetHeight, rowHeight || 0) || defaultSize;
114+
const res =
115+
arr.reduce((pv, c) => pv + c.offsetHeight, rowHeight || 0) || defaultSizeRef.current;
115116

116117
// update the calculated height ref
117118
cacheRef.current[dataIndex] = res;
118119
return res;
119120
},
120-
[uuid, data, rowHeight, defaultSize, generateKeyFromRow]
121+
[uuid, data, rowHeight, generateKeyFromRow]
121122
);
122123

123124
const updatePixelWidths = useCallback(() => {
@@ -275,10 +276,7 @@ const ListComponent = forwardRef(function (
275276
}
276277
});
277278

278-
const median = treeRef.current.getMedian();
279-
if (median && defaultSize !== median) {
280-
setDefaultSize(median);
281-
}
279+
defaultSizeRef.current = treeRef.current.getMedian();
282280
}}
283281
itemData={{
284282
rows: data,

0 commit comments

Comments
 (0)