How to pass data between child and parent in react-native?

后端 未结 6 1854
一生所求
一生所求 2020-12-30 07:49
module.exports= class APP extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      key1:\'key1\',
      key2:\'key2\'
    };
  rend         


        
6条回答
  •  不思量自难忘°
    2020-12-30 08:19

    To call Parent's method from child, you can pass the reference like this.

    Parent Class

     (this.parentReference = ref)}
        parentReference = {this.parentMethod.bind(this)}
    />
    
    parentMethod(data) {
    
    }
    

    Child Class

    let data = {
        id: 'xyz',
        name: 'zzz',
    };
    

    //This will call the method of parent

    this.props.parentReference(data);
    

提交回复
热议问题