I almost always have the constructor in my own apps because there's almost always a few other things happening there, so I've gotten too-much in the habit of starting with the constructor "by default". But you're right. It's doing nothing here. So I've removed it.
I just re-jiggered it so that saveCounter() is called first, as a side-effect of the existing state.counter value.
I agree with Michi on this one. Removing the prevState modifier removes the explicit indication that we're updating the current state in relation to previous state. And it's "hardly readable" without a space after the colon?? Meh. Poe-tay-toe / poe-tah-toe. Now we're getting into tabs-vs-spaces territory...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I almost always have the
constructor
in my own apps because there's almost always a few other things happening there, so I've gotten too-much in the habit of starting with theconstructor
"by default". But you're right. It's doing nothing here. So I've removed it.I just re-jiggered it so that
saveCounter()
is called first, as a side-effect of the existingstate.counter
value.I agree with Michi on this one. Removing the
prevState
modifier removes the explicit indication that we're updating the current state in relation to previous state. And it's "hardly readable" without a space after the colon?? Meh. Poe-tay-toe / poe-tah-toe. Now we're getting into tabs-vs-spaces territory...