MCPcopy Index your code
hub / github.com/reactive-python/reactpy / use_reducer

Function use_reducer

src/py/reactpy/reactpy/core/hooks.py:299–316  ·  view source on GitHub ↗

See the full :ref:`Use Reducer` docs for details Parameters: reducer: A function which applies an action to the current state in order to produce the next state. initial_value: The initial state value (same as for :func:`use_state`) Retur

(
    reducer: Callable[[_Type, _ActionType], _Type],
    initial_value: _Type,
)

Source from the content-addressed store, hash-verified

297
298
299def use_reducer(
300 reducer: Callable[[_Type, _ActionType], _Type],
301 initial_value: _Type,
302) -> tuple[_Type, Callable[[_ActionType], None]]:
303 """See the full :ref:`Use Reducer` docs for details
304
305 Parameters:
306 reducer:
307 A function which applies an action to the current state in order to
308 produce the next state.
309 initial_value:
310 The initial state value (same as for :func:`use_state`)
311
312 Returns:
313 A tuple containing the current state and a function to change it with an action
314 """
315 state, set_state = use_state(initial_value)
316 return state, _use_const(lambda: _create_dispatcher(reducer, set_state))
317
318
319def _create_dispatcher(

Callers

nothing calls this directly

Calls 3

use_stateFunction · 0.85
_use_constFunction · 0.85
_create_dispatcherFunction · 0.85

Tested by

no test coverage detected