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
6 changes: 3 additions & 3 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface CellProps<RecordType extends DefaultRecordType> {
ellipsis?: CellEllipsisType;
align?: AlignType;

shouldCellUpdate?: (record: RecordType) => boolean;
shouldCellUpdate?: (record: RecordType, prevRecord: RecordType) => boolean;

// Fixed
fixLeft?: number | false;
Expand Down Expand Up @@ -207,9 +207,9 @@ function Cell<RecordType extends DefaultRecordType>(
const RefCell = React.forwardRef<any, CellProps<any>>(Cell);
RefCell.displayName = 'Cell';

const MemoCell = React.memo(RefCell, (_, next: CellProps<any>) => {
const MemoCell = React.memo(RefCell, (prev: CellProps<any>, next: CellProps<any>) => {
if (next.shouldCellUpdate) {
return !next.shouldCellUpdate(next.record);
return !next.shouldCellUpdate(next.record, prev.record);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface ColumnType<RecordType> extends ColumnSharedType<RecordType> {
record: RecordType,
index: number,
) => React.ReactNode | RenderedCell<RecordType>;
shouldCellUpdate?: (record: RecordType) => boolean;
shouldCellUpdate?: (record: RecordType, prevRecord: RecordType) => boolean;
rowSpan?: number;
width?: number | string;
onCell?: GetComponentProps<RecordType>;
Expand Down
21 changes: 17 additions & 4 deletions tests/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,18 +965,24 @@ describe('Table.Basic', () => {
const record = { key: 1 };
let shouldUpdate = false;
let renderTimes = 0;
let prev;
let next;

const Demo = () => {
const Demo = ({ records }) => {
const [, forceUpdate] = React.useState({});

return (
<>
<Table
data={[record]}
data={records}
columns={[
{
dataIndex: 'key',
shouldCellUpdate: () => shouldUpdate,
shouldCellUpdate: (nextRecord, prevRecord) => {
next = nextRecord;
prev = prevRecord;
return shouldUpdate;
},
render() {
renderTimes += 1;
return null;
Expand All @@ -994,7 +1000,7 @@ describe('Table.Basic', () => {
);
};

const wrapper = mount(<Demo />);
const wrapper = mount(<Demo records={[record]} />);
renderTimes = 0;

wrapper.find('button').simulate('click');
Expand All @@ -1003,5 +1009,12 @@ describe('Table.Basic', () => {
shouldUpdate = true;
wrapper.find('button').simulate('click');
expect(renderTimes).toEqual(1);

// Should update match prev & next
const newRecord = { ...record, next: true };
wrapper.setProps({ records: [newRecord] });
// wrapper.update();
expect(prev).toBe(record);
expect(next).toBe(newRecord);
});
});