Skip to content

Commit fe98c50

Browse files
committed
Add comments, reset state if prop changes
1 parent c0b5e84 commit fe98c50

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/DataGrid.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
342342
const columnWidths = isColumnWidthsControlled ? columnWidthsRaw : columnWidthsInternal;
343343
const onColumnWidthsChange = isColumnWidthsControlled
344344
? (columnWidths: ColumnWidths) => {
345-
// we need to keep the columnWidths state and prop in sync otherwise it leads to bugs like
346-
// resize column, auto resize column, and resize column again will use the internal width.
345+
// we keep the internal state in sync with the prop but this prevents an extra render
347346
setColumnWidthsInternal(columnWidths);
348347
onColumnWidthsChangeRaw(columnWidths);
349348
}
@@ -1075,6 +1074,11 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
10751074
setDraggedOverRowIdx(undefined);
10761075
}
10771076

1077+
// Keep the state and prop in sync
1078+
if (isColumnWidthsControlled && columnWidthsInternal !== columnWidthsRaw) {
1079+
setColumnWidthsInternal(columnWidthsRaw);
1080+
}
1081+
10781082
let templateRows = `repeat(${headerRowsCount}, ${headerRowHeight}px)`;
10791083
if (topSummaryRowsCount > 0) {
10801084
templateRows += ` repeat(${topSummaryRowsCount}, ${summaryRowHeight}px)`;

0 commit comments

Comments
 (0)