React- Cannot read property 'setState' of undefined

前端 未结 3 1019
野的像风
野的像风 2021-02-14 08:11

for some reason, I\'m getting the error \" React- Cannot read property \'setState\' of undefined\". So this.state is never getting updated with the values that the user inputs.

3条回答
  •  花落未央
    2021-02-14 09:11

    If you use an arrow function then you won't need to bind.

    onNameChange = (e)=> {
    this.setState({name:e.target.value});
    }
    
    onPasswordChange = (e) => {
    this.setState({password:e.target.value});
    }
    

提交回复
热议问题