Uncaught TypeError: Cannot read property 'state' of undefined - React

后端 未结 2 1999
忘掉有多难
忘掉有多难 2021-01-22 05:22

I can not figure out if I am missing something small here?

Just trying to get a grasp on how state works with React.

Just creating a small check box that change

2条回答
  •  悲哀的现实
    2021-01-22 05:47

    Changes:

    1. You forgot to bind the onChange method, either use this:

    onChange={this.handleCheck.bind(this)}

    or define the binding in the constructor:

    this.handleCheck = this.handleCheck.bind(this)

    2. You used setState in a wrong way, setState is a method you need to call it.

    Instead of: this.setState = ({})

    it should be: this.setState({})

提交回复
热议问题