Component React component of PureComponent Function Component

Virtual DOM, through efficient algorithms do Diff finish ends of batch update section changes, all comparisons are shallow comparison shallowEqual. Everyone can not afford relatively deep, facebook own can not do -


Component: Be sure to supporting the use of shouldComponentUpdate, or props or state regardless of whether the update component must update

pureComponent: When the props and state assemblies unchanged, the component is not updated. Only need to replace component => pureComponent, ultra-high investment returns zero

function Component: write purely functional components are very simple and elegant, the government has also recommended such an approach. However, this does not mean pure function component is the best performance of components wording.
Is packaged into a method of StatelessComponent only render components in-house, will be updated in all cases.
(Facebook said to optimize StatelessComponent, to optimize its performance is also very simple, but they have not been optimized, do not know why. I learned later, had the ultimate solution, React Hook)
Therefore, it is not recommended to use write comparison complex components

to sum up:

PureComponent > StatelessComponent > Component

function Component vs PureCompoent, do not recommend more complex pages, use the function Component.

 

Referring know almost links: React Examples Analytical Performance Optimization component https://zhuanlan.zhihu.com/p/34632531

Guess you like

Origin www.cnblogs.com/ajaxkong/p/11419061.html