I dont know what im doing wrong

Tell us what’s happening:

  **Your code so far**

// Define ADD, addMessage(), messageReducer(), and store here:

const ADD = 'ADD';




const addMessage = (message) => {
return{
   message:message,
type:ADD
}

};



function messageReducer(state=[],action)
{
 switch (action.type)
 {
    case ADD:
    return [...state,action.message];
      break;
    default:
    return state;
    
 }


}
Redux.createStore(messageReducer);


  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0.

Challenge: Extract State Logic to Redux

Link to the challenge:

Instead of Redux.createStore(messageReducer); you should write:

const store = Redux.createStore(
   messageReducer, 
  []
);

One of the tests check for existence of the store and its initial value that should be an empty array. createStore takes 3 arguments - reducer, preloaded state and enhancer. You should set preloaded (or, in other words, initial) state to empty array.

But when I try to createStore with only first argument - message reducer - it doesn’t pass the tests

Nevermind, I made a typo creating store with one arg :wink: You’re completely right.
Btw to @99andri12

return{
   message:message,
type:ADD
}

can be shortened to

return{
   message,
type:ADD
}

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