LoginSignup
1
1

More than 5 years have passed since last update.

react native "this.setState is not a function"

Posted at

react native で"this.setState is not a function"と怒られる

APIのレスポンスを扱おうとした時にコールバック関数内でthis.setStateを使おうとしたらthis.setState is not a functionとエラーがでた。

ググると
https://stackoverflow.com/questions/31045716/react-this-setstate-is-not-a-function/31045750#31045750

こちらにたどり着いた。

どうやらcallback関数内のthisはグローバルのwindowオブジェクトを示してしまうらしいのでes6 のbind(this)をcallback関数につけることで本来参照したいthisを参照できる様になるらしい。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1