File tree Expand file tree Collapse file tree 5 files changed +59
-2
lines changed Expand file tree Collapse file tree 5 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -16,5 +16,6 @@ module.exports = {
16
16
'import/no-named-as-default-member' : 0 ,
17
17
'jsx-a11y/label-has-for' : 0 ,
18
18
'jsx-a11y/label-has-associated-control' : 0 ,
19
+ 'jsx-a11y/control-has-associated-label' : 0 ,
19
20
} ,
20
21
} ;
Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
158
158
index = { index }
159
159
dataIndex = { dataIndex }
160
160
render = { render }
161
+ shouldCellUpdate = { column . shouldCellUpdate }
161
162
{ ...fixedInfo }
162
163
appendNode = { appendCellNode }
163
164
additionalProps = { additionalCellProps }
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ export interface CellProps<RecordType extends DefaultRecordType> {
41
41
ellipsis ?: boolean ;
42
42
align ?: AlignType ;
43
43
44
+ shouldCellUpdate ?: ( record : RecordType ) => boolean ;
45
+
44
46
// Fixed
45
47
fixLeft ?: number | false ;
46
48
fixRight ?: number | false ;
@@ -197,7 +199,15 @@ function Cell<RecordType extends DefaultRecordType>(
197
199
) ;
198
200
}
199
201
200
- const RefCell = React . forwardRef ( Cell ) ;
202
+ const RefCell = React . forwardRef < any , CellProps < any > > ( Cell ) ;
201
203
RefCell . displayName = 'Cell' ;
202
204
203
- export default RefCell ;
205
+ const MemoCell = React . memo ( RefCell , ( _ , next : CellProps < any > ) => {
206
+ if ( next . shouldCellUpdate ) {
207
+ return ! next . shouldCellUpdate ( next . record ) ;
208
+ }
209
+
210
+ return false ;
211
+ } ) ;
212
+
213
+ export default MemoCell ;
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ export interface ColumnType<RecordType> extends ColumnSharedType<RecordType> {
79
79
record : RecordType ,
80
80
index : number ,
81
81
) => React . ReactNode | RenderedCell < RecordType > ;
82
+ shouldCellUpdate ?: ( record : RecordType ) => boolean ;
82
83
rowSpan ?: number ;
83
84
width ?: number | string ;
84
85
onCell ?: GetComponentProps < RecordType > ;
Original file line number Diff line number Diff line change @@ -925,4 +925,48 @@ describe('Table.Basic', () => {
925
925
) ;
926
926
} ) . not . toThrow ( ) ;
927
927
} ) ;
928
+
929
+ it ( 'shouldCellUpdate' , ( ) => {
930
+ const record = { key : 1 } ;
931
+ let shouldUpdate = false ;
932
+ let renderTimes = 0 ;
933
+
934
+ const Demo = ( ) => {
935
+ const [ , forceUpdate ] = React . useState ( { } ) ;
936
+
937
+ return (
938
+ < >
939
+ < Table
940
+ data = { [ record ] }
941
+ columns = { [
942
+ {
943
+ dataIndex : 'key' ,
944
+ shouldCellUpdate : ( ) => shouldUpdate ,
945
+ render ( ) {
946
+ renderTimes += 1 ;
947
+ return null ;
948
+ } ,
949
+ } ,
950
+ ] }
951
+ />
952
+ < button
953
+ type = "button"
954
+ onClick = { ( ) => {
955
+ forceUpdate ( { } ) ;
956
+ } }
957
+ />
958
+ </ >
959
+ ) ;
960
+ } ;
961
+
962
+ const wrapper = mount ( < Demo /> ) ;
963
+ renderTimes = 0 ;
964
+
965
+ wrapper . find ( 'button' ) . simulate ( 'click' ) ;
966
+ expect ( renderTimes ) . toEqual ( 0 ) ;
967
+
968
+ shouldUpdate = true ;
969
+ wrapper . find ( 'button' ) . simulate ( 'click' ) ;
970
+ expect ( renderTimes ) . toEqual ( 1 ) ;
971
+ } ) ;
928
972
} ) ;
You can’t perform that action at this time.
0 commit comments