React: this is null in event handler

后端 未结 4 1132
-上瘾入骨i
-上瘾入骨i 2020-12-28 12:21

I have a LoginForm component. I want to check before submit, that both loginName and password is set. I tried with this code (a lot of stuff omitte

4条回答
  •  被撕碎了的回忆
    2020-12-28 13:02

    For those who is using Babel, you can use bind operator with transform-function-bind plugin:

    onSubmit={::this.submit}
    

    which is a syntactic sugar for:

    onSubmit={this.submit.bind(this)}
    

提交回复
热议问题