Accessing event.target inside callback in react

前端 未结 4 1536
借酒劲吻你
借酒劲吻你 2020-11-28 14:00

I have the following class snippet:

constructor(props) {
    super(props);

    this.timeout = null;
}

search = (e) => {
    clearTimeout(this.timeout);
         


        
4条回答
  •  隐瞒了意图╮
    2020-11-28 14:39

    Try this:

    search = (e) => {
    e.persist();
    clearTimeout(this.timeout);
    this.timeout = setTimeout(
        function(){ console.log(e); alert(e) },
        500
    );
    

    }

    Judging from your code I think that you are using babel-plugin-transform-class-properties. In that case you don't need a constructor part.

提交回复
热议问题