edifice.use_context_select#
- edifice.use_context_select(context_key, selector)[source]#
Context shared state consumer for selected read-only shared state.
Use this Hook to consume state transmitted by the
provide_context()with the samecontext_key.Like
use_context(), but selects only part of theprovide_context()shared state, and cannot update the shared state.Provides similar features to React Redux useSelector.
- Parameters:
context_key (
str) – Identifier for a shared context.selector (
Callable[[TypeVar(_T_use_context)],TypeVar(_T_use_context_select)]) – A pure function which takes the shared context value and returns a selected part of the shared context value.
- Return type:
TypeVar(_T_use_context_select)- Returns:
A state value which is the selected part of the current shared context state value for the given
context_key.
use_context_select()is called with acontext_keyand aselectorfunction. It returns a state value.A
@componentwhich usesuse_context_select()will only re-render when the selected part of the context state value is not__eq__to the previous selected part.The
selectorfunction passed intouse_context_select()for the first render of the@componentwill be the one used for the lifetime of the@component.