Javascript 从父组件到子组件的传递函数不工作

Javascript 从父组件到子组件的传递函数不工作,javascript,reactjs,Javascript,Reactjs,该功能未触发。我检查了许多其他答案,似乎我的代码应该可以工作了 应用内父组件: update() { console.log("hello"); } <PrivateRoute exact path="/profile" component={Profile} update={this.update} /> <button type="button" onClick={this.prop

该功能未触发。我检查了许多其他答案,似乎我的代码应该可以工作了

应用内父组件:

update() {
  console.log("hello");
}

<PrivateRoute
  exact
  path="/profile"
  component={Profile}
  update={this.update}
/>
<button
  type="button"
  onClick={this.props.update}
>
update(){
console.log(“你好”);
}
在配置文件子组件中:

update() {
  console.log("hello");
}

<PrivateRoute
  exact
  path="/profile"
  component={Profile}
  update={this.update}
/>
<button
  type="button"
  onClick={this.props.update}
>

我认为在
PrivateRoute
中,您没有将
update
方法传递给
Profile
组件

const PrivateRoute = ({ component: Component, path: Path, ...rest }) => (
//...rest of your code

         //pass update prop along with other props which are needed.
          <Component update={rest.update} /> 

//...rest of your code
      );
    }}
  />
);
const PrivateRoute=({component:component,path:path,…rest})=>(
//…代码的其余部分
//将更新道具与其他需要的道具一起传递。
//…代码的其余部分
);
}}
/>
);

希望这有帮助。

请显示所有相关组件,而不仅仅是代码片段。您会遇到什么错误?这是!谢谢!:)