When you’re passing onClick handler you’re changing context from your component to a button element, meaning when your handler will be invoked this will refer to a button which in turn doesn’t have .setState method you will try to call. In order to fix it you basically have two options:
Explicetely bind this inside method to your component
Use class fields creating methods with arrow function:
Arrow function does not have concept of this and this inside arrow function always refers to outer context at declaration time, which will always be your component (exactly what you need).
You’re rewriting your method on every contruction event (when constructor is invoked). It’s nothing different than this:
Keep in mind that both approaches considered to be anti-pattern (bad practice) and it’s one of the reasons why React components should be just functions.
In my opininion, I think that if you don’t use this.handleClick = this.handleClick.bind(this) in React Class Component it cannot understand what to do when it doesn’t realize that where did you take the {this.handleClick} that you put it in your function. It seems like this is just another way to declare your variables.This is just what I thought!