edifice.use_context#
- edifice.use_context(context_key, value_type)[source]#
Context state consumer Hook for prop drilling.
Provides similar features to React useContext.
- Parameters:
context_key (
str
) – Identifier for a shared context.value_type (
type
[TypeVar
(_T_use_context
)]) – The type of the initial value in the parentprovide_context()
- Return type:
tuple
[TypeVar
(_T_use_context
),Callable
[[Union
[TypeVar
(_T_use_context
),Callable
[[TypeVar
(_T_use_context
)],TypeVar
(_T_use_context
)]]],None
]]- Returns:
A tuple pair containing
The current state value for the given
context_key
.A setter function for setting or updating the state value.
Use this Hook to consume state transmitted by the
provide_context()
with the samecontext_key
.use_context()
is called with acontext_key
and avalue_type
. It returns a state value and a setter function. The state value and setter function behave exactly like the ones documented inuse_state()
. Thevalue_type
must be the same as the type of the initial value in theprovide_context()
with the samecontext_key
.The setter function will, when called, update the state value across each
@component
usinguse_context()
with the samecontext_key
.