Table: Prevent runtime error when resizing columns with onColumnResize (#89862)

fix: prevent runtime error when resizing columns
This commit is contained in:
Galen Kistler 2024-07-09 07:08:35 -05:00 committed by GitHub
parent 8444c7760c
commit 20181425e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,12 +15,12 @@ export function useTableStateReducer({ onColumnResize, onSortByChange, data }: P
switch (action.type) {
case 'columnDoneResizing':
if (onColumnResize) {
const info = (newState.columnResizing.headerIdWidths as any)[0];
const columnIdString = info[0];
const info = (newState.columnResizing?.headerIdWidths as any)?.[0];
const columnIdString = info?.[0];
const fieldIndex = parseInt(columnIdString, 10);
const width = Math.round(newState.columnResizing.columnWidths[columnIdString]);
const width = Math.round(newState.columnResizing.columnWidths?.[columnIdString]);
const field = data.fields[fieldIndex];
const field = data.fields?.[fieldIndex];
if (!field) {
return newState;
}