Skip to content

Commit 672abc7

Browse files
committed
chore: Add more compare condition with memo
1 parent 4325f07 commit 672abc7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Table.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import * as React from 'react';
2828
import classNames from 'classnames';
29+
import shallowEqual from 'shallowequal';
2930
import warning from 'rc-util/lib/warning';
3031
import ResizeObserver from 'rc-resize-observer';
3132
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
@@ -78,12 +79,20 @@ interface MemoTableContentProps {
7879
children: React.ReactNode;
7980
pingLeft: boolean;
8081
pingRight: boolean;
82+
props: any;
8183
}
8284
const MemoTableContent = React.memo<MemoTableContentProps>(
8385
({ children }) => children as React.ReactElement,
84-
// No additional render when pinged status change.
85-
// This is not a bug.
86-
(prev, next) => prev.pingLeft !== next.pingLeft || prev.pingRight !== next.pingRight,
86+
87+
(prev, next) => {
88+
if (!shallowEqual(prev.props, next.props)) {
89+
return false;
90+
}
91+
92+
// No additional render when pinged status change.
93+
// This is not a bug.
94+
return prev.pingLeft !== next.pingLeft || prev.pingRight !== next.pingRight;
95+
},
8796
);
8897

8998
export interface TableProps<RecordType = unknown> extends LegacyExpandableProps<RecordType> {
@@ -627,7 +636,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
627636
ref={fullTableRef}
628637
{...ariaProps}
629638
>
630-
<MemoTableContent pingLeft={pingedLeft} pingRight={pingedRight}>
639+
<MemoTableContent pingLeft={pingedLeft} pingRight={pingedRight} props={props}>
631640
{title && <Panel className={`${prefixCls}-title`}>{title(mergedData)}</Panel>}
632641
<div className={`${prefixCls}-container`}>{groupTableNode}</div>
633642
{footer && <Panel className={`${prefixCls}-footer`}>{footer(mergedData)}</Panel>}

0 commit comments

Comments
 (0)