React class components and functions and components Hooks

React class components and functions and components Hooks

Author troubles will resolve their problem

 

 

We all know that the custom component has two requirements:

  1. Component name must begin with a capital letter

  2. 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:

 

image.png

 

 

What is a class component ▼

     Use ES6, class  components defined. As shown below:

image.png

 

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.image.png

 

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:

  1. Component name must begin with a capital letter

  2. 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:

 

image.png

 

 

What is a class component ▼

     Use ES6, class  components defined. As shown below:

image.png

 

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.image.png

 

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:image.png

 

Press attention two-dimensional code
ID: extreme Kan

qrcode_for_gh_a84046c76875_258 (1).jpg

 

 

Published 14 original articles · won praise 13 · views 3309

Guess you like

Origin blog.csdn.net/Raleway/article/details/104173497