this.setState is not a function

I’m taking a react course now. I stuck at composing components, 10 - removing the local state. I kept following Mosh and my code is exactly the same as his, but when I click at any button on a server, I keep getting this error: “TypeError: this.setState is not a function.” Please help)

Since you haven’t shared a piece of code.
Go to this link, see if that helps:


Thank you for sharing the resource. I tried to apply their fix-methods, but I am still stuck. I attached some screens below, it someone can help, I would be grateful.

Second screenshot. Line 24 ( this.setState = { counters }; ) is where the this.setState function is broken and it becomes an object. I think it should look like on line 19 ( this.setState({ counters }); ).

So I’ve downloaded the file that mosh attached at the introduction section of “Composing Component”, there is a start file and i wrote down the code from the scratch, it got rendered just fine.



Rendered Page:

However, you can send me the zip file of the yours so i can explore what is the problem

Thank you so much!!! I deleted the equal sign and now it works just fine)

Thank you for your help! I already solved my problem. My this.setState function was broken because I put “=” where it is not needed( I really appreciate your work. Thank you)

1 Like