File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -216,11 +216,13 @@ function Cell<RecordType extends DefaultRecordType>(
216
216
const RefCell = React . forwardRef < any , CellProps < any > > ( Cell ) ;
217
217
RefCell . displayName = 'Cell' ;
218
218
219
+ const comparePropList : ( keyof CellProps < any > ) [ ] = [ 'expanded' , 'className' ] ;
220
+
219
221
const MemoCell = React . memo ( RefCell , ( prev : CellProps < any > , next : CellProps < any > ) => {
220
222
if ( next . shouldCellUpdate ) {
221
223
return (
222
224
// Additional handle of expanded logic
223
- prev . expanded === next . expanded &&
225
+ comparePropList . every ( propName => prev [ propName ] === next [ propName ] ) &&
224
226
// User control update logic
225
227
! next . shouldCellUpdate ( next . record , prev . record )
226
228
) ;
Original file line number Diff line number Diff line change @@ -42,4 +42,32 @@ describe('Table.Cell', () => {
42
42
expect ( reRenderTime ) . toEqual ( 0 ) ;
43
43
}
44
44
} ) ;
45
+
46
+ it ( 'shouldCellUpdate not block className' , ( ) => {
47
+ let reRenderTime = 0 ;
48
+
49
+ const getColumns = ( props ?: object ) => [
50
+ {
51
+ shouldCellUpdate : ( record , prevRecord ) => prevRecord . key !== record . key ,
52
+ dataIndex : 'key' ,
53
+ render : value => {
54
+ reRenderTime += 1 ;
55
+ return value ;
56
+ } ,
57
+ ...props ,
58
+ } ,
59
+ ] ;
60
+
61
+ const wrapper = mount ( < Table data = { [ { key : 'light' } ] } columns = { getColumns ( ) } /> ) ;
62
+
63
+ // Update className should re-render
64
+ reRenderTime = 0 ;
65
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
66
+ wrapper . setProps ( {
67
+ columns : getColumns ( { className : 'test' } ) ,
68
+ } ) ;
69
+ }
70
+
71
+ expect ( reRenderTime ) . toEqual ( 1 ) ;
72
+ } ) ;
45
73
} ) ;
You can’t perform that action at this time.
0 commit comments