React Hooks Cheat Sheet
Bunlong
React Patterns Team#
State Management#
useState()Declare state.
Update state.
#
Side Effects#
useEffect()Triggers callback function only once when component is mounted.
Triggers callback function when dependency 'VALUE' is changed.
Cleanup side effects when component is unmounted.
#
Memoize a Callback#
useCallback()Return new function only when dependencies change.
Memoize callback for a dynamic list of elements.
#
Memoize a Value#
useMemo()Will trigger only when dependencies change.
#
Reference Element#
userRef()userRef is like a "BOX" that can hold a mutable value in its current property.
#
Context API#
useContext()Avoid props drilling using context API.
#
Manage State#
useReducer()Initialize a local state and create reducer.
Create local state and dispatch actions.
#
Create Your Own Custom HookCustom hooks must start with use
.