Extract State Logic to Redux (Problem with Dispatching addMessage)

Extract State Logic to Redux (Problem with Dispatching addMessage)
0

#1

Tell us what’s happening:

Hello, everyone.

So everything seems to be good except for one test:
Dispatching addMessage against the store should immutably add a new message to the array of messages held in state.

I can’t see why this isn’t working. I feel like I’ve either made a stupid mistake or I have a problem with my browser (Chrome). Any nudge in the right direction would be greatly appreciated!

Your code so far


// define ADD, addMessage(), messageReducer(), and store here:
const ADD = "ADD";
const addMessage = (message) =>{
  return{
    type: ADD,
    message: message
  }
}
const messageReducer = (state = [], action) =>{
  switch(action.type){
    case ADD:
    return {
      message: [...state, action.message]
    }
    break;
    default:
    return state;
  }
}

const store = Redux.createStore(messageReducer)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react-and-redux/extract-state-logic-to-redux/


#2

Yep. As I suspected, I made a silly mistake:

return [...state, action.message]

^That’s the correction I made and it passed.