Why create multiple reducers?
How would you combine multiple reducers?
combineReducers
method from Redux. This method accepts an object as its argument, and each key/value pair in the object will become a key/value pair in the Redux state.How will you manage state as an immutable object?
Object.assign()
method to create a new object with the updated state. This method accepts two arguments, the first being the object to be updated, and the second being the new state. The new state will overwrite the old state. This method will not mutate the original object.combineReducers
is a utility function to simplify the most common use case when writing Redux reducers
. It turns an object whose values are different reducing functions into a single reducing function you can pass to createStore
.
Explain how combineReducers
assembles the new state tree.
combineReducers
accepts an object full of slice reducer functions at its top level, and returns a new reducer function. When the new reducer is called, it calls each slice reducer with their current state and the current action, then it combines the results into a single state object. The state produced by combineReducers()
namespaces the states of each reducer under their keys as passed to combineReducers()
.How would you define initial state in an application?
Why will you want to split your reducing functions as your app becomes more complex?
The combineReducers
helper function turns an object whose values are different reducing functions into a single reducing function you can pass to createStore
. The resulting reducer calls every child reducer, and gathers their results into a single state object. The state produced by combineReducers()
namespaces the states of each reducer under their keys as passed to combineReducers()
.
What is a popular convention when naming reducers?
What are your learning goals after reading and reviewing the class README?