代码之家  ›  专栏  ›  技术社区  ›  bp123

从函数中触发事件

  •  0
  • bp123  · 技术社区  · 8 年前

    如何在函数中触发事件?在下面的示例中,当 componentDidUpdate 发射 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);
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Tholle    8 年前

    您正在从返回函数 handleFilterByClass 是的。删除 (event) => 如果你想直接调用它。

    handleFilterByClass = classId => {
      console.log(111);
    }