Please enable JavaScript.
Coggle requires JavaScript to display documents.
React Hooks and Advanced, useMemo & useCallback Reference
https…
React Hooks and Advanced
for performance
memo
-
-
-
use case
use when there's a pure component that receives (for example 2 props from a 4 props parent component, in which the parent component also receive a prop from another parent component
if the parent component changes the prop that doesn't related to the pure component, it will still re-render. So this is where you should use React.memo
-
useMemo
-
how to use
-
-
e.g
const myArray = useMemo(() => array, [whenToChange])
-
useCallback
-
how to use it
just like useMemo, but first argument goes to the function directly
e.g
const myFunction = useCallback(myFun, [whenToChange])
-
-
-
for state management
useReducer
-
use case
-
-
toggle a state (true to false, false to true)
how to use
-
-
e.g
[value, toggle] = useReducer(value => !value, true)
toggle()
[value, toggle] = useReducer((value, newValue) => ({...value, ...newValue}, {})
toggle(myNewValue)
[value, reducer] = useReducer((state, action) => otherReduxLikeFancyStuffs)
-
-