Please enable JavaScript.
Coggle requires JavaScript to display documents.
React: Context and useContext - Coggle Diagram
React: Context and useContext
Introduction
what is it
replace for
redux
global state management
why use it
darn simple usage
concept
1 context = 1 value
createContext
what is it for
creating context
setting initial value
note for initial value
only use it if you're not giving value in the Provider
better solution
Context.Provider value={}
Provider
what is it for
implementing created context
natures
all children have access to the value
useContext
what is it for
retrieving value from context
how to use it
const value = useContext(MyContext)
import the
MyContext
!
what about changing values
pass
setState
to the context as pair of [state, setState]
mimic useState/useReducer as the provider's value
e.g
https://gist.github.com/audipasuatmadi/9ba1e02b26cfd7e7b731a7d95762237a