Skip to content

Commit

Permalink
fix: not expanded for rerender
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 18, 2023
1 parent 134b88a commit e4e2e40
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Body/BodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecordType> {
record: RecordType;
Expand Down Expand Up @@ -116,18 +116,14 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
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 = (
<RowComponent
Expand Down Expand Up @@ -181,7 +177,7 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(

// ======================== 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);
Expand Down

0 comments on commit e4e2e40

Please sign in to comment.