@@ -3,9 +3,9 @@ import * as React from 'react';
3
3
import Cell from '../Cell' ;
4
4
import { responseImmutable } from '../context/TableContext' ;
5
5
import devRenderTimes from '../hooks/useRenderTimes' ;
6
+ import useRowInfo from '../hooks/useRowInfo' ;
6
7
import type { ColumnType , CustomizeComponent , GetRowKey } from '../interface' ;
7
8
import ExpandedRow from './ExpandedRow' ;
8
- import useRowInfo from '../hooks/useRowInfo' ;
9
9
10
10
export interface BodyRowProps < RecordType > {
11
11
record : RecordType ;
@@ -116,18 +116,14 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
116
116
rowSupportExpand,
117
117
} = rowInfo ;
118
118
119
- const [ expandRended , setExpandRended ] = React . useState ( false ) ;
119
+ // Force render expand row if expanded before
120
+ const expandedRef = React . useRef ( false ) ;
121
+ expandedRef . current ||= expanded ;
120
122
121
123
if ( process . env . NODE_ENV !== 'production' ) {
122
124
devRenderTimes ( props ) ;
123
125
}
124
126
125
- React . useEffect ( ( ) => {
126
- if ( expanded ) {
127
- setExpandRended ( true ) ;
128
- }
129
- } , [ expanded ] ) ;
130
-
131
127
// ======================== Base tr row ========================
132
128
const baseRowNode = (
133
129
< RowComponent
@@ -181,7 +177,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
181
177
182
178
// ======================== Expand Row =========================
183
179
let expandRowNode : React . ReactElement ;
184
- if ( rowSupportExpand && ( expandRended || expanded ) ) {
180
+ if ( rowSupportExpand && ( expandedRef . current || expanded ) ) {
185
181
const expandContent = expandedRowRender ( record , index , indent + 1 , expanded ) ;
186
182
const computedExpandedRowClassName =
187
183
expandedRowClassName && expandedRowClassName ( record , index , indent ) ;
0 commit comments