Challenge: Render Conditionally from Props
Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/react/render-conditionally-from-props
I was following hte freeCodeCamp React Tutorial and when completing the challenge " React: Render Conditionally from Props" I wonder why I can manipulate the counter value in the state by adding + 1
but not by incrementing it ++
.
The code which I’m refering to:
handleClick() {
this.setState(state => ({
counter: state.counter + 1 // works fine
//counter: state.counter++ // doesn't work
}));
}
Is this because ++
would mutate the state directly? Or am I missing something?