score:3

Accepted answer

Because

counter: props.counter + 1

means create label named counter. However, you indeed never use this label after.

You probably wanted

this.setState((prevState, props) => ({
  counter: props.counter + 1
}));

Note, that you just need to wrap {} in arrow function with parenthesis. Otherwise {} is considered as function body block and not an object returned from this function function, which you want in your case.


Related Query

More Query from same tag