Cannot read property 'target' of undefined

前端 未结 6 1228
感动是毒
感动是毒 2020-12-31 11:03

In my render method I have component


handleChange is fol

6条回答
  •  耶瑟儿~
    2020-12-31 11:42

    The problem is that you are invoking the function in this line:

    onChange={this.handleChange()}
    

    All you have to do is simply pass the function as a value to onChange without invoking it.

    onChange={this.handleChange}
    

    When you use parenthesis you'd be invoking a function/method instead of binding it with an event handler. Compare the following two examples:

    //invokes handleChange() and stores what the function returns in testA.
    const testA = this.handleChange()  
    

    vs

    //stores the function itself in testB. testB be is now a function and may be invoked - testB();
    const testB = this.handleChange 
    

提交回复
热议问题