ReactJS: Control a child state from the child and the parent

前端 未结 2 1363
情歌与酒
情歌与酒 2021-02-19 16:19

I have a rather simple problem and I\'m not sure how to solve it with React\'s one way data flow.

Say you have a link in the parent that shows a modal

In the mod

2条回答
  •  失恋的感觉
    2021-02-19 17:22

    You could pass a callback as a prop to the child component:

    // In the parent
    
    
    // In the modal
    
    × ...

    Then when you click the close button on the child, it will call the function of the parent

提交回复
热议问题