Redux : Send Action Data to store

Send Action Data to Store


I am stuck on this problem for a long time. I think my code is correct , but somehow it is not passing all the tests. I am sharing my code . Can any body help me find the issue please


Link to the problem


const ADD_NOTE = 'ADD_NOTE';

const notesReducer = (state = 'Initial State', action) => {
  switch(action.type) {
    // Change code below this line
    case ADD_NOTE : return { text: action.text}
    // Change code above this line
    default:
      return state;
  }
};


const addNoteText = (note) => {
  // Change code below this line
  return {
    type : ADD_NOTE,
    text : note
  }
  // Change code above this line
};

const store = Redux.createStore(notesReducer);

console.log(store.getState());
store.dispatch(addNoteText('Hello!'));
console.log(store.getState());
2 Likes

The problem is here:

case ADD_NOTE : return { text: action.text}

The instructions say:

This case should be triggered whenever there is an action of type ADD_NOTE and it should return the text property on the incoming action as the new state .

" return the text property … as the new state" is the key phrase. You haven’t done that, you’ve wrapped it in an object. True, that is a very common pattern in redux, for your reducer state to be an object, but that is not what is asked here. For this leaf on the redux state tree, the string is the state.

When I fix that, the code passes for me.

1 Like

Thank you for helping me out. :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.