Javascript ReactJS onClick参数未传递给父组件
我有一个具有注入式Mobx存储的组件,该存储具有以下方法:Javascript ReactJS onClick参数未传递给父组件,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,我有一个具有注入式Mobx存储的组件,该存储具有以下方法: 构造函数(道具){ 超级(道具) 此.state={ propertyChangeNotifications:true, 消息提示:错误 } } updateNotifications=(类型、值)=>{ this.props.uiStore.updateProfile(类型、值) }我认为应该传递函数本身,而不是“调用函数”。在这里删除() 问题是,在所有要绑定该方法的地方,都要两次,一次使用 this.updateNotifica
构造函数(道具){
超级(道具)
此.state={
propertyChangeNotifications:true,
消息提示:错误
}
}
updateNotifications=(类型、值)=>{
this.props.uiStore.updateProfile(类型、值)
}
我认为应该传递函数本身,而不是“调用函数”。在这里删除()
问题是,在所有要绑定该方法的地方,都要两次,一次使用
this.updateNotifications={() => this.updateNotifications()} //here you are calling the function with no parameter.
及
updateNotifications = () =>
updateNotifications = () =>
只要把第一条路从所有的地方移开,它就行了
只需使用:
this.updateNotifications={this.updateNotifications}
并使用箭头函数定义函数
:
updateNotifications = () =>