React class components and functions and components Hooks
Author troubles will resolve their problem
We all know that the custom component has two requirements:
-
Component name must begin with a capital letter
-
Return Value component only one root element
What is the function of the component ▼
Function component receives a single props
object and returns a React element, as shown below:
What is a class component ▼
Use ES6, class components defined. As shown below:
Function component and difference component class ▼
There was a time standard answer is: class components can access more features (such as status). With Hook , it is no longer the case.
Performance than the performance of a function component class components must be high, because the components used when the class to be instantiated, and the function returns the assembly to take direct execution result to the function. To improve performance, make use of the function components.
What is Hook ▼
Hook is a new feature React 16.8. It allows you to use the state as well as other React characteristics without writing class is. That after React 16.8 function components can react using state and other characteristics. Specific learning hook go https://react.docschina.org/docs/hooks-intro.html
After the components have hook function programming projects so react better performance, the code more compact.
React class components and functions and components Hooks
Author troubles will resolve their problem
We all know that the custom component has two requirements:
-
Component name must begin with a capital letter
-
Return Value component only one root element
What is the function of the component ▼
Function component receives a single props
object and returns a React element, as shown below:
What is a class component ▼
Use ES6, class components defined. As shown below:
Function component and difference component class ▼
There was a time standard answer is: class components can access more features (such as status). With Hook , it is no longer the case.
Performance than the performance of a function component class components must be high, because the components used when the class to be instantiated, and the function returns the assembly to take direct execution result to the function. To improve performance, make use of the function components.
What is Hook ▼
Hook is a new feature React 16.8. It allows you to use the state as well as other React characteristics without writing class is. That after React 16.8 function components can react using state and other characteristics. Specific learning hook go https://react.docschina.org/docs/hooks-intro.html
After the components have hook function programming projects so react better performance, the code more compact. The following demo:
Press attention two-dimensional code
ID: extreme Kan