I came across some code defining the state of a component inside a class, for example:
The way I learned React was to declare a state inside the class constructor:
The only difference I can think of is that state initialization in the constructor guarantees the correct state initialization in the component life cycle.
What is the difference between two pieces of code? In fragment 1, is it possible to assume that the state should be correctly set when the class is initialized?
source share