combineReducers
can be used to combine multiple reducers, where the default values are set in the reducer state
arguementnewState = {…state}; return newState
state = {…state, property: action.payload} //desctructure the state object, and only alter the property of interest in that action
combineReducer()
is a utility function to simplify the most common use case when writing Redux Reducers.combineReducers()
first call each slice reducer with its current slice of the state and the current action, and give the slice a chance to respond to the state if needed. So all reducers to get called when combineReducers()
is used.createStore
which takes in the preoadedState
. This initialize the setore with state that was previously presisted elsewhere in the app or browser’s localstorage.combineReducer
helper function turns an object whose values are different reducing functions into a single reducing function you can pass to createStore
.combineReducers({ counter, todos })
is equivalent to combineReducers({ counter: counter, todos: todos })