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 same context_key.

Like use_context(), but selects only part of the provide_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 a context_key and a selector function. It returns a state value.

A @component which uses use_context_select() will only re-render when the selected part of the context state value is not __eq__ to the previous selected part.

The selector function passed into use_context_select() for the first render of the @component will be the one used for the lifetime of the @component.