[英]Pass down function from parent component to child component is not working
The function is not triggering. function 未触发。 I checked many other answers and it seems like my code should be working.
我检查了许多其他答案,看来我的代码应该可以工作。
In App parent component:在 App 父组件中:
update() {
console.log("hello");
}
<PrivateRoute
exact
path="/profile"
component={Profile}
update={this.update}
/>
In Profile child component:在 Profile 子组件中:
<button
type="button"
onClick={this.props.update}
>
I think in PrivateRoute
you are not passing update
method to Profile
component.我认为在
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
);
}}
/>
);
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.