I'm new to React, how come I get [object Object] all the time? #21526
-
Hi! So recently I was studying React, on a website project. I don’t have the github files yet, as an error occurred, but here is my counter.jsx file:
And my index.js file:
So the problem is, whenever I click the Increment button, I always get: How do I get rid of the [object Object]1? Thank you,
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I’m on mobile so apologies for lack of formatting. You are incrementing the state object instead of increment the count property: Your code: this.state + 1 |
Beta Was this translation helpful? Give feedback.
-
Thank you @badsyntax! It helped for me!! |
Beta Was this translation helpful? Give feedback.
I’m on mobile so apologies for lack of formatting. You are incrementing the state object instead of increment the count property:
Your code: this.state + 1
Should be: this.state.count + 1