Reducers

Actions only specify what has happened but do not specify what is the effect of that action on the application state. The reducer function specifies how the application state is changed. It is a pure function that takes the two arguments—previous state and an action—and returns the next updated state.

(previousState, action) =>newState

Things you should never do inside a reducer:

  • Modify its arguments
  • API calls and routing
  • Call other non-pure functions, for example, Date.now()

In Redux, a single object represents the application state. So, before we write any code, it is very important to think and decide the structure of the application state object.

It is recommended that we keep our state object as normalized as possible and avoid nesting of objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset