React HOOK2

React HOOK rules:

Hooks can only appear at the top level.
Don’t call hooks in loops, conditions, or nested functions.
Insert picture description here
Insert picture description here

PureComponet and memo

PureComponet usage:
Insert picture description here
memo usage
Insert picture description here

userCallback

Insert picture description here
Insert picture description here

useReducer

Insert picture description here

useContext

Insert picture description here

Insufficient React Hooks

Although we have seen the power of React Hooks through the above examples, it seems that class components can be completely rewritten using React Hooks. However, in the current v16.8 version, the two life cycle functions in class components, getSnapshotBeforeUpdate and componentDidCatch, cannot be implemented yet. The official also plans to implement it in React Hooks in the near future.

Guess you like

Origin blog.csdn.net/QZ9420/article/details/112802711