API から 401 が返されたときにコンポーネントにエラー メッセージを表示したい。何にもバインドされていない状態を使用しようとしており、ES6 を使用しています。私は得ています
Cannot read property 'setState' of undefined
これはログイン機能です:
login(e) {
e.preventDefault();
AuthService.login(this.state.username, this.state.password)
.catch(function (err) {
console.log(err);
this.setState({loginFailed: true});
});
}