How does the React ant.design Modal dialog box trigger the action of a subcomponent?

how to trigger an action in a child component through the parent component in the React.


import {Modal} from "antd"

<Modal
  visible={this.state.componentModalVisible}
  title=""
  onOk={this.handleOk}
  onCancel={this.handleCancel}
  footer={[
    <Button key="back" onClick={this.handleCancel}></Button>,
    <Button key="submit" type="primary" onClick={this.handleOk}></Button>
  ]}>
  <Child /> // ``state
</Modal>
Mar.20,2021

the parent component can only get the state, of the child component through the callback function, for example:

getData = (data)=>{
    console.log('data',data)
}

<child getData={this.getData} />

// child

onClick={()=>{
    const data = this.state.data;
    this.props.getData(data);
}}

the parent component can be dropped from the component using ref.
for example:

//
<Modal
  visible={this.state.componentModalVisible}
  title=""
  onOk={this.ref.child.handleClick}
  onCancel={this.handleCancel}
  footer={[
    <Button key="back" onClick={this.handleCancel}></Button>,
    <Button key="submit" type="primary" onClick={this.handleOk}></Button>
  ]}>
  <Child ref={(c)=>{this.child=c}} /> // ``state
</Modal>

//
handleClick(){
    //...
}

since the save button is in the parent component, why not all the information to be saved and the methods used also exist in the parent component? Then the this in the parent component is passed to the child component, and the child component can get the data or change the data through the props.

< Child parent= {this} / > / here the this of the parent component is passed to the child component;

/ / the child component passes through
this.props.parent.state. Parent component data; / get parent component data
this.props.parent.setState ({parent component data: new data}); / / change parent component data
this.props.parent. Parent component method; / / call parent component method

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e50253-275c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e50253-275c8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?