@@ -3,9 +3,9 @@ import * as React from 'react';
33import Cell from '../Cell' ;
44import { responseImmutable } from '../context/TableContext' ;
55import devRenderTimes from '../hooks/useRenderTimes' ;
6+ import useRowInfo from '../hooks/useRowInfo' ;
67import type { ColumnType , CustomizeComponent , GetRowKey } from '../interface' ;
78import ExpandedRow from './ExpandedRow' ;
8- import useRowInfo from '../hooks/useRowInfo' ;
99
1010export interface BodyRowProps < RecordType > {
1111 record : RecordType ;
@@ -116,18 +116,14 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
116116 rowSupportExpand,
117117 } = rowInfo ;
118118
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 ;
120122
121123 if ( process . env . NODE_ENV !== 'production' ) {
122124 devRenderTimes ( props ) ;
123125 }
124126
125- React . useEffect ( ( ) => {
126- if ( expanded ) {
127- setExpandRended ( true ) ;
128- }
129- } , [ expanded ] ) ;
130-
131127 // ======================== Base tr row ========================
132128 const baseRowNode = (
133129 < RowComponent
@@ -181,7 +177,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
181177
182178 // ======================== Expand Row =========================
183179 let expandRowNode : React . ReactElement ;
184- if ( rowSupportExpand && ( expandRended || expanded ) ) {
180+ if ( rowSupportExpand && ( expandedRef . current || expanded ) ) {
185181 const expandContent = expandedRowRender ( record , index , indent + 1 , expanded ) ;
186182 const computedExpandedRowClassName =
187183 expandedRowClassName && expandedRowClassName ( record , index , indent ) ;
0 commit comments