Multiple Reducers with Redux Reducers – Redux React Tutorial #4



Once your store is in place, you'll want to set up multiple Redux reducers to act on parts of your data store. Redux reducers are great in that they are only aware of part of your data, and the rest of the data is neither reachable nor able to be mutated by your reducer.

GET THE CODE! https://github.com/learncodeacademy/react-js-tutorials

Reducers are a great concept in Redux, because they allow your react application to have specific pieces of data that all update synchronously. All reducers run against your Redux store, and then the store triggers a change event and your entire React.js application re-renders.

The biggest thing to keep in mind with Redux reducers is you don't want to mutate your state. ALWAYS return a new state rather than mutating the old state values.

code source

  • Question, so I 100% agree that you should not mutate the state, but isn't the reason that when you open both of the objects at 5:00 because chrome doesn't evaluate an object's properties in the console until you examine it? I'm pretty sure if you printed out each of the fields instead of the object itself, it'd display the correct values.

    As I said, I definitely support what you're saying, but I think this is a key fact that can't be ignored in this case– it's not that the state was somehow mutated before it even ran through the second reducer, it's just that the state refers to the same object, so when you print it out twice, if you mutate it in between the logs, both logs will appear to have the same properties and values because they're only evaluated upon expansion.

    View Comment
  • First !!

    View Comment