useReducer<S, A> function

BloomReducer<S, A> useReducer<S, A>(
  1. BloomReducerFn<S, A> reducerFn,
  2. S initialState
)

Creates a BloomReducer with the given reducerFn and initialState.

Convenience factory named to mirror React's useReducer(reducer, initialState) convention. Returns a state container wrapping a reactive Signal driven by reducerFn.

Example

final counter = useReducer<int, String>(
  (count, action) => action == 'inc' ? count + 1 : count - 1,
  0,
);

counter.dispatch('inc');
print(counter.state.value); // 1

Implementation

BloomReducer<S, A> useReducer<S, A>(
  BloomReducerFn<S, A> reducerFn,
  S initialState,
) {
  return BloomReducer<S, A>(reducerFn, initialState);
}