Extract State Logic to Redux 4

Tell us what’s happening:

Dispatching addMessage against the store should immutably add a new message to the array of messages held in state.

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) 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/react-and-redux/extract-state-logic-to-redux/

1 Like

When I rename the defaultStatus to initial, it’s work!

1 Like

I wonder if “default” is a key term and that’s why initial works? This doesn’t make sense to me, Thank you so much I have been struggling with “The store should exist and have an initial state set to an empty array.” failing for hours you post helped I was using “defaultStatus” too.