useReducer<State, Action> function

Store<State, Action> useReducer<State, Action>(
  1. Reducer<State, Action> reducer, {
  2. required State initialState,
  3. required Action initialAction,
})

An alternative to useState for more complex states.

useReducer manages a read only instance of state that can be updated by dispatching actions which are interpreted by a Reducer.

reducer is immediately called on first build with initialAction and initialState as parameter.

It is possible to change the reducer by calling useReducer with a new Reducer.

See also:

Implementation

Store<State, Action> useReducer<State, Action>(
  Reducer<State, Action> reducer, {
  required State initialState,
  required Action initialAction,
}) {
  return use(
    _ReducerHook(
      reducer,
      initialAction: initialAction,
      initialState: initialState,
    ),
  );
}