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

后端 未结 6 1849
一生所求
一生所求 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:07

    class Parent extends Component{
       constructor(props){
       super(props);
        this.state={value:''};
        this.getData=this.getData.bind(this);
      }
    
      getData(val){
       console.log(val);
      this.setState({
        value:val
      });
      }
        render(){
          const {value}=this.state
        return(
          
          
          
            
        {this.state.value};
        
          
          
        )
        }
    }
    export default Parent;
    
    
    CHILD CLASS:
    
    class Child extends Component{
       componentWillMount(){
        this.props.sendData('data');
       }
        render(){ 
        return(
              
           
        )
        }  
    }
    export default Child;
    

提交回复
热议问题