redux reducer not updating state

Viewed 15641

I am new to Redux, and reading through the documentation while I try to make a basic to do list.

I can't seem to get my reducer to add an item to the list. The correct action creator is firing, I think there is perhaps something in my Object.assign statement that I am not understanding. Below is my store.js file.

const defaultState = {
    todos:[
  {
    text: 'walk gilbert'
  },
  {
    text: 'cook dinner'
  },
  {
    text: 'clean bathroom'
  }
 ]
}

function todos(state = defaultState) {
  return state;
}

function modifyList(state = defaultState, action) {
  switch(action.type) {
    case 'ADD_TODO':
    return Object.assign({}, state, {
        todos: [
          ...state.todos,
        {
            text: action.text,
        }
      ]
    })

  default:
    return state;
 }
}

const rootReducer = combineReducers({todos, modifyList})

const store = createStore(rootReducer, defaultState);

export default store;

Thanks!

1 Answers
Related