2. Comparison of two ways to create the module system
Note: Use components to create the class keyword has its own private data (this.state) and life cycle functions;
Note: Use components function created only props, not have their own private data and lifecycle functions;
1. Create out with the constructor components: [assembly is called a stateless stateless components with very little]
2. Create a key component out of a class is called stateful component [most] with
3. Under what circumstances the use of stateful components? Stateless components under what circumstances?
-
If a component needs to have its own private data is recommended: stateful components class created;
-
If a component does not require proprietary data, it is recommended, stateless component;
-
React official said: stateless components, the absence of their own state and lifecycle functions, so the efficiency of the components will be slightly higher than the state and a number;
There are essential differences between state and non-state component assembly is: whether the state property and the availability of life-cycle function
4. The difference between the assembly props and state / data
-
Data props in the outside world are passed over;
-
state / data in the data are private component; (ajax data acquired by the back are generally private data)
-
Data props are read-only and can not be reassigned;
-