https://ko.react.dev/reference/react/useContext
useContext
is a React Hook that lets you read and subscribe to context from your component.
useContext(SomeContext)
SomeContext
****
createContext
.useContext
returns the context value for the calling component.value
passed to the closest SomeContext.Provider
above the calling component in the tree.defaultValue
createContext
for that context.useContext()
call in a component is not affected by providers returned from the same component.
<aside>
💡 The corresponding <Context.Provider>
needs to be above the component doing the useContext()
call.
</aside>
React automatically re-renders all the children that use a particular context starting from the provider that receives a different value
.
If your build system produces duplicates modules in the output (which can happen with symlinks), this can break context.
SomeContext
that you use to provide context and SomeContext
that you use to read it are exactly the same object, as determined by a ===
comparison.