Reactjs 从函数中触发事件
如何在函数中触发事件?在下面的示例中,当Reactjs 从函数中触发事件,reactjs,Reactjs,如何在函数中触发事件?在下面的示例中,当componentdiddupdate触发this.testHandle()时,但是this.handleFilterByClass()根本不触发。我想这与事件有关。我错过了什么 componentDidUpdate(prevProps, prevState) { if (prevProps.studentUserProfiles.length !== this.props.studentUserProfiles.length) { this.
componentdiddupdate
触发this.testHandle()
时,但是this.handleFilterByClass()
根本不触发。我想这与事件有关。我错过了什么
componentDidUpdate(prevProps, prevState) {
if (prevProps.studentUserProfiles.length !== this.props.studentUserProfiles.length) {
this.handleFilterByClass();
this.testHandle();
}
}
testHandle() {
console.log('testHandle');
}
handleFilterByClass = classId => (event) => {
console.log(111);
}
您正在从
handleFilterByClass
返回一个函数。如果希望能够直接调用它,请删除(事件)=>
handleFilterByClass = classId => {
console.log(111);
}
您的
handleFilterByClass
正在返回一个函数。尝试编写this.handleFilterByClass()代码>作为实验。将出现错误的handleFilterByClass=classId=>(事件)=>{
更改为handleFilterByClass:classId=>(事件)=>{
@dysfunc@dysfunc这也会出错。`handleFilterByClass:classId=>(事件)=>{`我想您正在寻找这个`handleFilterByClass(classId){console.log(classId)}`我收到此错误。`无法在现有状态转换期间更新(例如在render
或其他组件的构造函数中)渲染方法应该是道具和状态的纯函数;构造函数副作用是一种反模式,但是可以移动到组件> />代码> ``bp123,这与你的问题无关。考虑用A创建另一个问题,我们可以帮助你。