useContext(). No prop threading required.
createContext()
Create a context object that can hold a typed value.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
defaultValue | T | Value returned by useContext() when no Provider is active |
Returns
Context<T> — an object with a Provider method for providing values and internal state for useContext() lookups.
useContext()
Read the current value from the nearest Provider in the component tree.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context<T> | The context to read from |
Returns
The current context value from the nearest Provider, the default value if no Provider is active, orundefined if neither exists.
Provider
Provide a value to all descendants. Two usage patterns are supported:JSX usage
Callback usage
Pattern: typed accessor hook
Always create ause* wrapper that throws on missing Provider. This gives consumers a clear error instead of silent undefined.