Combining reducers

Now, all that is left to do is combining these two reducers together to handle the whole state and all actions of the application:

function appReducer (state = {}, action) {  return {    posts: postsReducer(state.posts, action),    filter: filterReducer(state.filter, action),  }}

The default state for our app is an empty object, {}. We create the state object by passing the substates and actions down to our other reducers. On initialization, these reducers get passed undefined, because state.posts and state.filter do not exist, yet. As a result, the default state defined in the subreducers will be used.

When the Redux store gets created from the appReducer function, Redux passes an @@redux/INIT action with an undefined state to ...

Get Learning Redux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.