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

后端 未结 18 2646
清歌不尽
清歌不尽 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:20

    Arrow function could have make your life more easier to avoid binding this keyword. Like so:

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

提交回复
热议问题