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 parent provide_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

  1. The current state value for the given context_key.

  2. A setter function for setting or updating the state value.

Use this Hook to consume state transmitted by the provide_context() with the same context_key.

use_context() is called with a context_key and a value_type. It returns a state value and a setter function. The state value and setter function behave exactly like the ones documented in use_state(). The value_type must be the same as the type of the initial value in the provide_context() with the same context_key.

The setter function will, when called, update the state value across each @component using use_context() with the same context_key.