rootReducerintermediatefunction rootReducer(state = {}, action) {
return {
counter: counterReducer(state.counter, action),
name: nameReducer(state.name, action),
}
}Manually building a root reducer clarifies how combineReducers works under the hood.
A root reducer combines multiple sub-reducers by manually routing state slices:
function rootReducer(state = {}, action) {
return {
counter: counterReducer(state.counter, action),
name: nameReducer(state.name, action),
}
}
Each sub-reducer only sees and manages its own slice. The root reducer assembles the final state object.
Challenge: Implement counterReducer, nameReducer, and rootReducer that compose them together.