@@ -31,15 +31,17 @@ function Body<RecordType>({
31
31
emptyNode,
32
32
childrenColumnName,
33
33
} : BodyProps < RecordType > ) {
34
- const [ startRow , setStartRow ] = React . useState ( - 1 ) ;
35
- const [ endRow , setEndRow ] = React . useState ( - 1 ) ;
36
34
const { onColumnResize } = React . useContext ( ResizeContext ) ;
37
35
const { prefixCls, getComponent } = React . useContext ( TableContext ) ;
38
36
const { flattenColumns } = React . useContext ( BodyContext ) ;
39
37
40
38
const flattenData : { record : RecordType ; indent : number ; index : number } [ ] =
41
39
useFlattenRecords < RecordType > ( data , childrenColumnName , expandedKeys , getRowKey ) ;
42
40
41
+ // ====================== Hover =======================
42
+ const [ startRow , setStartRow ] = React . useState ( - 1 ) ;
43
+ const [ endRow , setEndRow ] = React . useState ( - 1 ) ;
44
+
43
45
const onHover = React . useCallback ( ( start : number , end : number ) => {
44
46
setStartRow ( start ) ;
45
47
setEndRow ( end ) ;
@@ -50,7 +52,8 @@ function Body<RecordType>({
50
52
[ onHover , startRow , endRow ] ,
51
53
) ;
52
54
53
- return React . useMemo ( ( ) => {
55
+ // ====================== Render ======================
56
+ const bodyNode = React . useMemo ( ( ) => {
54
57
const WrapperComponent = getComponent ( [ 'body' , 'wrapper' ] , 'tbody' ) ;
55
58
const trComponent = getComponent ( [ 'body' , 'row' ] , 'tr' ) ;
56
59
const tdComponent = getComponent ( [ 'body' , 'cell' ] , 'td' ) ;
@@ -98,20 +101,18 @@ function Body<RecordType>({
98
101
const columnsKey = getColumnsKey ( flattenColumns ) ;
99
102
100
103
return (
101
- < HoverContext . Provider value = { hoverContext } >
102
- < WrapperComponent className = { `${ prefixCls } -tbody` } >
103
- { /* Measure body column width with additional hidden col */ }
104
- { measureColumnWidth && (
105
- < MeasureRow
106
- prefixCls = { prefixCls }
107
- columnsKey = { columnsKey }
108
- onColumnResize = { onColumnResize }
109
- />
110
- ) }
111
-
112
- { rows }
113
- </ WrapperComponent >
114
- </ HoverContext . Provider >
104
+ < WrapperComponent className = { `${ prefixCls } -tbody` } >
105
+ { /* Measure body column width with additional hidden col */ }
106
+ { measureColumnWidth && (
107
+ < MeasureRow
108
+ prefixCls = { prefixCls }
109
+ columnsKey = { columnsKey }
110
+ onColumnResize = { onColumnResize }
111
+ />
112
+ ) }
113
+
114
+ { rows }
115
+ </ WrapperComponent >
115
116
) ;
116
117
} , [
117
118
data ,
@@ -127,8 +128,9 @@ function Body<RecordType>({
127
128
onColumnResize ,
128
129
rowExpandable ,
129
130
flattenData ,
130
- hoverContext ,
131
131
] ) ;
132
+
133
+ return < HoverContext . Provider value = { hoverContext } > { bodyNode } </ HoverContext . Provider > ;
132
134
}
133
135
134
136
const MemoBody = React . memo ( Body ) ;
0 commit comments