Redux - Combined Reducers

Overview

Redux excels at not only global state, but complex global state. Today, we’ll be using multiple reducers to manage separate parts of the store

Class Outline

Learning Objectives

Students will be able to

Describe and Define

Execute

Notes

Combined Reducers

Combined reducers is nothing more than pulling in more than one reducer from source and creating a keyed object from them.

import todoReducer from './todo.store.js';
import itemReducer from './item.store.js';

let reducers = combineReducers({
  todo: todoReducer,
  item: itemReducer,
});

Once done, any component can reach into the store and get either one, both, or all …

import * as actions from "../../store/todo.store.js";
import * as itemActions from "../../store/item.store.js";

const mapStateToProps = state => ({
  todo: state.todo,
  item: state.item,
});

const mapDispatchToProps = (dispatch, getState) => ({
  deleteItem: id => dispatch(actions.deleteItem(id)),
  hideDetails: id => dispatch(itemActions.hideDetails()),
});

What’s the point?

What about the actions?