You can manage your family at any time, but when problems are dealing with issues such as defense, infrastructure, law, order, group society so-called society always appoints someone who is responsible for these problems It must be. When there is a state
In addition, problems with macro management, control, regulation, and symmetrical allocation of resources require some sort of central decision-making body to make it oligarchy, hegemony, democracy, dictatorship / kingdom . In the central decision making process, we have a state
To use state objects, you must first initialize them. Since the state object is a simple instance property, it can be initialized in the constructor of the Button class. Define only the usual constructor (React receives props object) and call super method to keep track of component inheritance. This is simple and powerful. We have defined an event handler for the onClick method. The handleClick function is executed each time the user clicks the button. This function reads the current state of the counter value, increments it, and then sets that state to the new increment value. Since React is responsible for all necessary rendering after these changes, there is no need to worry about this.
I will learn about the state. Where do I initialize? The state of React, unlike the one passed in, is independent for some components. Since there is a vote in the state, we are in initialization state as the collection of products we have is generated by us. Do this before the render () method:} The state of React should be considered immutable. In other words, please do not change directly. The above function uses JavaScript Object.assign (); by creating a seemingly new array called nextProducts. This is similar to the current state, but the number of votes has changed. Next nextProducts is set to the new state. It seems strange to do this, but that's why the React team proposes to improve performance.