growthmindsit

Redux - Combined Reducers

Review, Research, and Discussion

  1. Why choose Redux instead of the Context API for global state? Context API Resourceful and ideal for small applications where state changes are minimal but Redux Perfect for larger applications where there are high-frequency state updates
  2. What is the purpose of a reducer? The reducer takes two parameters: state and action. You need to have an initial value so that when Redux calls the reducer for the first time with undefined, it will return the initialState. Then the function uses a switch statement to determine which type of action it’s dealing with. If there is an unknown action, then it should return the state, so that the application doesn’t lose its current state.
  3. What does an action contain?Actions are objects that have a type property and any other data that it needs to describe the action(payload).
  4. Why do we need to copy the state in a reducer? to avoid losing existing data

Document the following Vocabulary Terms

Preparation Materials

CombineReducers mutates an object whose values are different reducer functions into a single function, which then can be passed to createStore. This combineReducers function calls every child reducer and collects their results into a single state object. This state object “namespaces” the states updated from each reducer with the keys.

Multiple Reducers Example

Redux Docs: Using Combined Reducers

Redux Docs: Combined Reducer Syntax

Github view