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创建另一个问题,我们可以帮助你。