Search⌘ K
AI Features

Reducers

Explore how reducers function as pure, side-effect-free functions that manage immutable state in Redux. Understand how reducers handle actions to safely update application state, enabling predictable state changes in Angular apps using NgRx.

Introduction to reducers

Reducers are a general programming concept. They are not Redux-specific.

A reducer is a function that has the following characteristics:

  • Reducers are pure functions.
  • Reducers don’t create any side effects.
  • Reducer functions receive some data as arguments and perform an immutable operation on them.

Let’s understand the characteristics above one by one.

Pure and impure functions

Pure functions always return the same output for the same given arguments.

In the following example, we declare a function, sum(), which receives two arguments, a and b, and returns a+b. For the same values of ...