useReducer<T, A> function

Reactive<T> useReducer<T, A>(
  1. T initialState,
  2. T reducer(
    1. T state,
    2. A action
    )
)

Creates a reducer-style state manager.

Implementation

Reactive<T> useReducer<T, A>(
    T initialState, T Function(T state, A action) reducer) {
  final state = Reactive<T>(initialState);

  void dispatch(A action) {
    state.value = reducer(state.value, action);
  }

  // Attach dispatch function to the reactive state
  (state as dynamic).dispatch = dispatch;

  return state;
}