reducer<State, Action> method

(State, void Function(Action)) reducer<State, Action>(
  1. Reducer<State, Action> reducer,
  2. State initialState
)

A simple implementation of the reducer pattern as a side effect.

The React docs do a great job of explaining the reducer pattern more. See https://react.dev/reference/react/useReducer

Implementation

(State, void Function(Action)) reducer<State, Action>(
  Reducer<State, Action> reducer,
  State initialState,
) {
  final (currState, setState) = use.state(initialState);
  return (
    currState,
    (action) => setState(reducer(currState, action)),
  );
}