I have a some question about how to access props or state in promise. I have username password input and one button.The actionClickSignIn function work when i click button.Then i click button it show error
"TypeError: Cannot read property 'props' of undefined"
i want to know how to access props or state in UserAuth. Thankyou
my constructor
this.actionClickSignIn = this.actionClickSignIn.bind(this);
my function , UserAuth is using axois
actionClickSignIn() {
let {username,password} = this.state;
this.props.setName("John") // --- > It work !!!!
UserAuth(username,password).then(function(res){
this.props.setName(res.data.user.name) //---> not work !!!!
this.state.isLogin = true
}).catch(function (error) {
console.log(error);
});
}
and reder function
<Button type="button" onClick={this.actionClickSignIn}> Sign In</Button>