Send Action Data to the Store

Whenever I’m trying to click on run tests, the button isn’t working. I can’t figure out if my code is wrong or if it is a bug.


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};
                      break;
      default: return state;
               break;
    // 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());

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/redux/send-action-data-to-the-store/

You are changing the shape of your reducer.

You start with a state: String === 'Initial State, but after your ADD_NOTE action you are returning an object with key - value --> text : action.text

Perhaps what you want to achieve is to
return state as a new string that is equal to action.text?

Hope it helps :slight_smile:

Also you have two default cases in your switch.

2 Likes

Thanks a lot :slight_smile:
It worked. I didn’t understood the problem carefully that’s why I think I was doing it in a wrong way.

case ADD_NOTE : return state = action.text;

1 Like

If you read carefully, the challenge is asking

and it should return the text property on the incoming action as the new state

which simply means

return action.text;
1 Like