react.js call parent function from child

前端 未结 3 2090
小蘑菇
小蘑菇 2021-01-12 02:16

I know there are a few similar questions here and here but I am having a tough time understanding what is the correct thinking today on this and extrapolating it to my situa

3条回答
  •  花落未央
    2021-01-12 02:19

    call parent function from child

    You don't (like what the other posts say). You pass handleScoreRemove into the child as a prop. Inside the child, you call the function by calling the prop. In the following, handleScoreRemove is passed as the onScoreRemove prop inside the child.

    
    

    You're already doing the same thing with the ScoreBox (parent) and ScoreForm (child). You're passing a reference of handleScoreSubmit as onScoreSubmit prop in the child.

    
    

提交回复
热议问题