After the ant-design, nested subtable (expandedRowRender) acquires the data asynchronously, the redrawing after setState will continue to initiate pleas.

problem description

our company uses Ali"s ant-design open source framework, and now there is a need to nest tables in the table. After the user clicks on a row of data in the parent table, get the key, of that row and then asynchronously request the backend data to fill in the contents of the child table.

related codes

/ / the extraneous code
import {sidetransferDetail} from"@ services/payCenter";
export default class serial extends PureComponent {
state= {

has been omitted.
  secData:"",//

}
/ / details table
expandedRowRender = (record, index, indent, expanded) = > {

let credentialsNum=record.credentialsNum //key
let sendData={
    num:credentialsNum
}
sidetransferDetail(sendData)  //ajax
  .then((res)=>{
      this.setState({
         secData:res.data,
      })
  })
  return (
      <Table
        columns={secColumns}
        dataSource={this.state.secData}
        pagination={false}
      />
    );

};
render () {

    return(
      <Card>
          {this.renderForm()}
          <div>
             <Table
                    expandedRowRender={this.expandedRowRender}
                    loading={loading}
                    rowSelection={rowSelection}
                    dataSource={list}
                    columns={columns}
                    pagination={paginationProps}
                    scroll={{ x: 2500}}
                    size = "middle" 
                    expandRowByClick={true}
                    onSelect={this.seFn}
                  />
          </div>
      </Card>
    ) 
}

}

actual content

clipboard.png

clipboard.png

Aug.11,2021

I ventured to make a summary of the answer upstairs, and successfully realized

.
onExpand = (expanded, record) => {
    const { dispatch } = this.props;
 
    if (expanded === false) {
      // 
      // 
      console.log("");
      this.setState({
        subTabData: {
          ...this.state.subTabData,
          [record.contract_id]: [] ,
        }
      });
    } else {
      console.log("");
      dispatch({
        type: 'flow/getPlanList',
        payload: {
          contractId: record.contract_id,
        },
        callback: () => {
          const {
            flow: { data },
          } = this.props; 
 
          this.setState({
            subTabData: {
              ...this.state.subTabData,
              [record.contract_id]: data.list ,
            }
          });
 
          console.log("(PlanList):" + JSON.stringify(this.state.subTabData));
        }
      });
    }
  }
For more information, please see https://blog.csdn.net/z3y3m3/.

.

expandedRowRender is actually using ajax in the, React render called in the render method of the Table component, which can cause repeated calls, ajax-> setState-> render-> ajax-> setState-> render, loop.
should put ajax in onExpand.

Menu