React and Redux - Extract State Logic to Redux

React and Redux - Extract State Logic to Redux
0

#1

What am I doing wrong? I’m getting an error: Uncaught TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

I’m using the deploy site (https://deploy-preview-80–freecodecamp-learn.netlify.com/front-end-libraries/react-and-redux/extract-state-logic-to-redux) since the beta site is broken, but I think the deploy site is broken, too.

const ADD = 'ADD';

function addMessage(msg){
    return {
        type: ADD,
        message: msg
    };
};

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

const store = Redux.createStore(messageReducer);

//optionally store.dispatch(addMessage())

#2

I think it’s because of the comma instead your switch, which should be a semicolon instead:

    switch(action.type){
        case ADD: return [...state, action.message], // This comma should be a semicolon
        default: return state
    };

On a somewhat related note, I think it’s good practice to write your return statement in the next line and indented because it’s easier to read and debug. I hope that helps! :smile:


#3

that was it. silly mistake. tyvm


#4

A post was split to a new topic: Problem with Extract State Logic to Redux