From e4e2e404b02ba194e040fa9b4ba9b0e15ee8da65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 18 Sep 2023 15:20:39 +0800 Subject: [PATCH] fix: not expanded for rerender --- src/Body/BodyRow.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Body/BodyRow.tsx b/src/Body/BodyRow.tsx index baf6f9e5f..928d3b808 100644 --- a/src/Body/BodyRow.tsx +++ b/src/Body/BodyRow.tsx @@ -3,9 +3,9 @@ import * as React from 'react'; import Cell from '../Cell'; import { responseImmutable } from '../context/TableContext'; import devRenderTimes from '../hooks/useRenderTimes'; +import useRowInfo from '../hooks/useRowInfo'; import type { ColumnType, CustomizeComponent, GetRowKey } from '../interface'; import ExpandedRow from './ExpandedRow'; -import useRowInfo from '../hooks/useRowInfo'; export interface BodyRowProps { record: RecordType; @@ -116,18 +116,14 @@ function BodyRow( rowSupportExpand, } = rowInfo; - const [expandRended, setExpandRended] = React.useState(false); + // Force render expand row if expanded before + const expandedRef = React.useRef(false); + expandedRef.current ||= expanded; if (process.env.NODE_ENV !== 'production') { devRenderTimes(props); } - React.useEffect(() => { - if (expanded) { - setExpandRended(true); - } - }, [expanded]); - // ======================== Base tr row ======================== const baseRowNode = ( ( // ======================== Expand Row ========================= let expandRowNode: React.ReactElement; - if (rowSupportExpand && (expandRended || expanded)) { + if (rowSupportExpand && (expandedRef.current || expanded)) { const expandContent = expandedRowRender(record, index, indent + 1, expanded); const computedExpandedRowClassName = expandedRowClassName && expandedRowClassName(record, index, indent);