Call child method from parent

前端 未结 16 2095
长发绾君心
长发绾君心 2020-11-21 22:23

I have two components.

  1. Parent component
  2. Child component

I was trying to call child\'s method from Parent, I tried this way but couldn\

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-21 23:22

    Alternative method with useEffect:

    Parent:

    const [refresh, doRefresh] = useState(0);
    

    Children:

    useEffect(() => {
        performRefresh(); //children function of interest
      }, [props.refresh]);
    

提交回复
热议问题