React - uncaught TypeError: Cannot read property 'setState' of undefined

后端 未结 18 2555
清歌不尽
清歌不尽 2020-11-22 13:35

I am getting the following error

Uncaught TypeError: Cannot read property \'setState\' of undefined

even after binding delta in

18条回答
  •  醉梦人生
    2020-11-22 14:23

    This error can be resolved by various methods-

    • If you are using ES5 syntax, then as per React js Documentation you have to use bind method.

      Something like this for the above example:

      this.delta = this.delta.bind(this)

    • If you are using ES6 syntax,then you need not use bind method,you can do it with something like this:

      delta=()=>{ this.setState({ count : this.state.count++ }); }

提交回复
热议问题