How to pass state back to parent in React?

后端 未结 7 1412
时光说笑
时光说笑 2020-12-05 04:08

I have a form that has a submit button. That form calls a function onclick that sets the state of something from false to true. I then want to pass this state back to the pa

7条回答
  •  暖寄归人
    2020-12-05 04:50

    Here is an example of how we can pass data from child to parent (I had the same issue and use come out with this )

    On parent, I have a function (which I will call from a child with some data for it)

    handleEdit(event, id){ //Fuction
        event.preventDefault();  
        this.setState({ displayModal: true , responseMessage:'', resId:id, mode:'edit'});  
     } 
    
    dishData =  this.handleEdit(event, id)}/>;
    

    At the child component :

    this.props.onEdit(event, listElement.id) } className="btn btn-success">

提交回复
热议问题