Why is this not being accepted? action.payload

Why is this not being accepted? action.payload
Considering that action is an object, why can’t I access the payload this way?

Your code so far


// Define ADD, addMessage(), messageReducer(), and store here:
const ADD = 'ADD';

const addMessage = (msg) => {
return {
    type: ADD,
    payload: msg
}
};

const messageReducer = (state = [], action) => {
switch(action.type) {
    case ADD:
        return {
            ...state,
            action.payload
        }
    default: return state;
}
}

const store = Redux.createStore(messageReducer);

Your browser information:

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

Challenge: Extract State Logic to Redux

Link to the challenge:

I think you should return “message” rather than “payload: msg” in addMessage function.
and then, your return type of messageReducer function, should be the type of an array. like below.

    type: ADD,

    message // also message: message

        return [

            ...state,

            action.message

        ]

hope it helps you.

1 Like

Thank you Jack628. I will try to focus on the solution, instead of why what doesn’t work doesn’t work… will get there eventually I guess. Thank you.

1 Like

you can focus on the errors given by compiler. it will help you find your errors.
thanks for your attention

2 Likes