Skip to main content

The Reducers

🔄 Reducers – Pure State Updates​

A reducer is a pure function that updates a specific part of the state in response to an action.

✨ Key Principles​

Reducers:

  • Take the current state and an action
  • Return a new state
  • Must be pure — no side effects, service calls, or randomness
  • Are called after effects, if any exist

🚫 Async Tips​

Reducers may return Task<TState>, but should avoid unnecessary await.

IncrementReducer.cs
internal class IncrementReducer : IReducer<CounterState, IncrementCounterResultAction>
{
public Task<CounterState> ReduceAsync(CounterState state, IncrementCounterResultAction action)
=> Task.FromResult(state with
{
Count = action.Count
});
}