in React JS by
Q:

  What are reducers in redux?

closed

▼ Show 1 Answer

+1 vote
by
 
Best answer

The reducer is a pure function that takes the previous state and an action, and returns the next state.

(previousState, action) => newState

It's called a reducer because it's the type of function you would pass to Array.prototype.reduce(reducer, ?initialValue). It's very important that the reducer stays pure. Things you should never do inside a reducer:

  • Mutate its arguments;
  • Perform side effects like API calls and routing transitions;
  • Call non-pure functions, e.g. Date.now() or Math.random().
React JS
Learn More with Madanswer

Related questions

0 votes
asked Jun 19, 2020 in React JS by JackTerrance
...