React. this.setState is not a function inside setTimeout

Posted by Jennifer | Updated on

React. this.setState is not a function inside setTimeout. You are loosing context. Use arrow function as simple way to preserve proper execution context:

Remember that anonymous function will have context window inside, unless you explicitly bind it with Function.prototype.bind. So here is another way to solve this problem:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers