Home > AI > Frontend > Redux >

combineReducers()

Create a reducer

Example 1:

const reducer = Redux.combineReducers({
  todos: (state = [], action) => {
    const newState = Object.assign([], state);
    if (action.type == 'add') {
        newState.push(action.item);
    }
    if (action.type == 'remove') {
        newState.splice(action.index, 1);
    }
    return newState;
    }
});

Leave a Reply