Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ function Cell<RecordType extends DefaultRecordType>(
const RefCell = React.forwardRef<any, CellProps<any>>(Cell);
RefCell.displayName = 'Cell';

const comparePropList: (keyof CellProps<any>)[] = ['expanded', 'className'];

const MemoCell = React.memo(RefCell, (prev: CellProps<any>, next: CellProps<any>) => {
if (next.shouldCellUpdate) {
return (
// Additional handle of expanded logic
prev.expanded === next.expanded &&
comparePropList.every(propName => prev[propName] === next[propName]) &&
// User control update logic
!next.shouldCellUpdate(next.record, prev.record)
);
Expand Down
28 changes: 28 additions & 0 deletions tests/Cell.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,32 @@ describe('Table.Cell', () => {
expect(reRenderTime).toEqual(0);
}
});

it('shouldCellUpdate not block className', () => {
let reRenderTime = 0;

const getColumns = (props?: object) => [
{
shouldCellUpdate: (record, prevRecord) => prevRecord.key !== record.key,
dataIndex: 'key',
render: value => {
reRenderTime += 1;
return value;
},
...props,
},
];

const wrapper = mount(<Table data={[{ key: 'light' }]} columns={getColumns()} />);

// Update className should re-render
reRenderTime = 0;
for (let i = 0; i < 10; i += 1) {
wrapper.setProps({
columns: getColumns({ className: 'test' }),
});
}

expect(reRenderTime).toEqual(1);
});
});