useState

1. Sequential memory

2. Cannot exist in a conditional statement

useEffect

1. UseEffect is an anonymous method. UseEffect is asynchronous and has a delayed action.

UseEffect corresponds to the two life cycle functions componetDidMount and componentDidUpdate in the class component

3. UseEffect The second parameter

(1) If the second parameter is null, the unbinding function will be executed only when the component is destroyed. If there is no second parameter, the unbinding function will be executed all the time.Copy the code

4. When useEffect’s second parameter is not empty,

useContext

CountContext = createContext()

2, the child component uses useContext to accept the value, useContext(CountContext), which is passed by the context, into useContext

useReducer

1. The useReducer has two parameters. The first parameter is the Reducer function, and the second parameter is the initial state of the current operation

2. The first reducer function has two values, state and action.

3, The entire useReducer returns two arguments, the first is the count value, and the second is the dispatch dispatcher, which passes an action

UseReducer, useContext implementation Redux

UseMemo addresses performance issues

UseMemo has two parameters, the first parameter is an anonymous method, and the second parameter is a variable that controls the execution of the anonymous method. If the parameter changes, it is not executedCopy the code

useRef

1. Get the DOM element

2. Save variables

Custom function

1, must use the beginning

UseCallback caches our methods, useMemo caches our state