Skip to content

Commit 8bb0404

Browse files
authored
fix: Update memo logic (#433)
* Fix memo logic * update memo
1 parent 85effcd commit 8bb0404

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Table.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
365365

366366
// Convert map to number width
367367
const colsKeys = getColumnsKey(flattenColumns);
368-
const colWidths = colsKeys.map(columnKey => colsWidths.get(columnKey));
368+
const pureColWidths = colsKeys.map(columnKey => colsWidths.get(columnKey));
369+
const colWidths = React.useMemo(() => pureColWidths, [pureColWidths.join('_')]);
369370
const stickyOffsets = useStickyOffsets(colWidths, flattenColumns.length, direction);
370371
const fixHeader = hasData && scroll && validateValue(scroll.y);
371372
const fixColumn = scroll && validateValue(scroll.x);
@@ -636,7 +637,11 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
636637
ref={fullTableRef}
637638
{...ariaProps}
638639
>
639-
<MemoTableContent pingLeft={pingedLeft} pingRight={pingedRight} props={props}>
640+
<MemoTableContent
641+
pingLeft={pingedLeft}
642+
pingRight={pingedRight}
643+
props={{ ...props, stickyOffsets }}
644+
>
640645
{title && <Panel className={`${prefixCls}-title`}>{title(mergedData)}</Panel>}
641646
<div className={`${prefixCls}-container`}>{groupTableNode}</div>
642647
{footer && <Panel className={`${prefixCls}-footer`}>{footer(mergedData)}</Panel>}

src/hooks/useStickyOffsets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function useStickyOffsets(colWidths: number[], columCount: number, direction: 'l
3737
left: leftOffsets,
3838
right: rightOffsets,
3939
};
40-
}, [colWidths, columCount]);
40+
}, [colWidths, columCount, direction]);
4141

4242
return stickyOffsets;
4343
}

0 commit comments

Comments
 (0)