Skip to content

Commit b497648

Browse files
committed
-1 loop
1 parent 833b52d commit b497648

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/hooks/useColumnWidths.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,20 @@ export function useColumnWidths<R, SR>(
8888

8989
function handleColumnResize(column: CalculatedColumn<R, SR>, nextWidth: ResizedWidth) {
9090
const { key: resizingKey } = column;
91-
const columnsToMeasure: string[] = [];
92-
93-
// remeasure all columns that can flex and are not resized by the user
94-
for (const { key, width } of viewportColumns) {
95-
if (
96-
columnsCanFlex &&
97-
resizingKey !== key &&
98-
typeof width === 'string' &&
99-
!resizedColumnWidths.has(key)
100-
) {
101-
columnsToMeasure.push(key);
102-
}
103-
}
10491

105-
if (columnsToMeasure.length > 0) {
106-
setMeasuredColumnWidths((measuredColumnWidths) => {
92+
setMeasuredColumnWidths((measuredColumnWidths) => {
93+
if (columnsCanFlex) {
10794
const newMeasuredColumnWidths = new Map(measuredColumnWidths);
108-
for (const columnKey of columnsToMeasure) {
109-
newMeasuredColumnWidths.delete(columnKey);
95+
for (const { key, width } of viewportColumns) {
96+
if (resizingKey !== key && typeof width === 'string' && !resizedColumnWidths.has(key)) {
97+
newMeasuredColumnWidths.delete(key);
98+
}
11099
}
111100
return newMeasuredColumnWidths;
112-
});
113-
}
101+
}
102+
103+
return measuredColumnWidths;
104+
});
114105

115106
setColumnToAutoResize({
116107
key: resizingKey,

0 commit comments

Comments
 (0)