1
- import { useContext } from '@rc-component/context' ;
1
+ import { responseImmutable , useContext } from '@rc-component/context' ;
2
2
import * as React from 'react' ;
3
3
import type { PerfRecord } from '../context/PerfContext' ;
4
4
import PerfContext from '../context/PerfContext' ;
5
5
import TableContext from '../context/TableContext' ;
6
6
import useFlattenRecords from '../hooks/useFlattenRecords' ;
7
+ import devRenderTimes from '../hooks/useRenderTimes' ;
7
8
import type { GetComponentProps , GetRowKey , Key } from '../interface' ;
8
9
import { getColumnsKey } from '../utils/valueUtil' ;
9
10
import BodyRow from './BodyRow' ;
@@ -21,16 +22,22 @@ export interface BodyProps<RecordType> {
21
22
childrenColumnName : string ;
22
23
}
23
24
24
- function Body < RecordType > ( {
25
- data,
26
- getRowKey,
27
- measureColumnWidth,
28
- expandedKeys,
29
- onRow,
30
- rowExpandable,
31
- emptyNode,
32
- childrenColumnName,
33
- } : BodyProps < RecordType > ) {
25
+ function Body < RecordType > ( props : BodyProps < RecordType > ) {
26
+ if ( process . env . NODE_ENV !== 'production' ) {
27
+ devRenderTimes ( props ) ;
28
+ }
29
+
30
+ const {
31
+ data,
32
+ getRowKey,
33
+ measureColumnWidth,
34
+ expandedKeys,
35
+ onRow,
36
+ rowExpandable,
37
+ emptyNode,
38
+ childrenColumnName,
39
+ } = props ;
40
+
34
41
const { prefixCls, getComponent, onColumnResize, flattenColumns } = useContext ( TableContext , [
35
42
'prefixCls' ,
36
43
'getComponent' ,
@@ -47,58 +54,57 @@ function Body<RecordType>({
47
54
} ) ;
48
55
49
56
// ====================== Render ======================
50
- const bodyNode = React . useMemo ( ( ) => {
51
- const WrapperComponent = getComponent ( [ 'body' , 'wrapper' ] , 'tbody' ) ;
52
- const trComponent = getComponent ( [ 'body' , 'row' ] , 'tr' ) ;
53
- const tdComponent = getComponent ( [ 'body' , 'cell' ] , 'td' ) ;
54
- const thComponent = getComponent ( [ 'body' , 'cell' ] , 'th' ) ;
57
+ const WrapperComponent = getComponent ( [ 'body' , 'wrapper' ] , 'tbody' ) ;
58
+ const trComponent = getComponent ( [ 'body' , 'row' ] , 'tr' ) ;
59
+ const tdComponent = getComponent ( [ 'body' , 'cell' ] , 'td' ) ;
60
+ const thComponent = getComponent ( [ 'body' , 'cell' ] , 'th' ) ;
55
61
56
- let rows : React . ReactNode ;
57
- if ( data . length ) {
58
- rows = flattenData . map ( ( item , idx ) => {
59
- const { record, indent, index : renderIndex } = item ;
62
+ let rows : React . ReactNode ;
63
+ if ( data . length ) {
64
+ rows = flattenData . map ( ( item , idx ) => {
65
+ const { record, indent, index : renderIndex } = item ;
60
66
61
- const key = getRowKey ( record , idx ) ;
67
+ const key = getRowKey ( record , idx ) ;
62
68
63
- return (
64
- < BodyRow
65
- key = { key }
66
- rowKey = { key }
67
- record = { record }
68
- recordKey = { key }
69
- index = { idx }
70
- renderIndex = { renderIndex }
71
- rowComponent = { trComponent }
72
- cellComponent = { tdComponent }
73
- scopeCellComponent = { thComponent }
74
- expandedKeys = { expandedKeys }
75
- onRow = { onRow }
76
- getRowKey = { getRowKey }
77
- rowExpandable = { rowExpandable }
78
- childrenColumnName = { childrenColumnName }
79
- indent = { indent }
80
- />
81
- ) ;
82
- } ) ;
83
- } else {
84
- rows = (
85
- < ExpandedRow
86
- expanded
87
- className = { `${ prefixCls } -placeholder` }
88
- prefixCls = { prefixCls }
89
- component = { trComponent }
69
+ return (
70
+ < BodyRow
71
+ key = { key }
72
+ rowKey = { key }
73
+ record = { record }
74
+ index = { idx }
75
+ renderIndex = { renderIndex }
76
+ rowComponent = { trComponent }
90
77
cellComponent = { tdComponent }
91
- colSpan = { flattenColumns . length }
92
- isEmpty
93
- >
94
- { emptyNode }
95
- </ ExpandedRow >
78
+ scopeCellComponent = { thComponent }
79
+ expandedKeys = { expandedKeys }
80
+ onRow = { onRow }
81
+ getRowKey = { getRowKey }
82
+ rowExpandable = { rowExpandable }
83
+ childrenColumnName = { childrenColumnName }
84
+ indent = { indent }
85
+ />
96
86
) ;
97
- }
87
+ } ) ;
88
+ } else {
89
+ rows = (
90
+ < ExpandedRow
91
+ expanded
92
+ className = { `${ prefixCls } -placeholder` }
93
+ prefixCls = { prefixCls }
94
+ component = { trComponent }
95
+ cellComponent = { tdComponent }
96
+ colSpan = { flattenColumns . length }
97
+ isEmpty
98
+ >
99
+ { emptyNode }
100
+ </ ExpandedRow >
101
+ ) ;
102
+ }
98
103
99
- const columnsKey = getColumnsKey ( flattenColumns ) ;
104
+ const columnsKey = getColumnsKey ( flattenColumns ) ;
100
105
101
- return (
106
+ return (
107
+ < PerfContext . Provider value = { perfRef . current } >
102
108
< WrapperComponent className = { `${ prefixCls } -tbody` } >
103
109
{ /* Measure body column width with additional hidden col */ }
104
110
{ measureColumnWidth && (
@@ -111,27 +117,10 @@ function Body<RecordType>({
111
117
112
118
{ rows }
113
119
</ WrapperComponent >
114
- ) ;
115
- } , [
116
- data ,
117
- prefixCls ,
118
- onRow ,
119
- measureColumnWidth ,
120
- expandedKeys ,
121
- getRowKey ,
122
- getComponent ,
123
- emptyNode ,
124
- flattenColumns ,
125
- childrenColumnName ,
126
- onColumnResize ,
127
- rowExpandable ,
128
- flattenData ,
129
- ] ) ;
130
-
131
- return < PerfContext . Provider value = { perfRef . current } > { bodyNode } </ PerfContext . Provider > ;
120
+ </ PerfContext . Provider >
121
+ ) ;
132
122
}
133
123
134
- const MemoBody = React . memo ( Body ) ;
135
- MemoBody . displayName = 'Body' ;
124
+ Body . displayName = 'Body' ;
136
125
137
- export default MemoBody ;
126
+ export default responseImmutable ( Body ) ;
0 commit comments