0

I am trying to update the state of an item in the store.

This is working but it is not returning the state in the format I am looking for.

The state looks like this:

state : {
   watchList: [
      {
        movie: {
          'name' : 'Batman'
        }
      }
   ]
}

however, I have been attempting to make my state look like this (i.e. not have another object inside the first object, but just an array of objects).

state : {

   watchList: [{'name' : 'Batman'}. {'name': 'Superman'}]

}

My reducer looks like this:

export default (state = [], action) => {

    switch(action.type) {

    case 'MOVIE_ADDED_TO_LIST':
        return [
            ...state,
            {
                movie: movie.event
            }
        ];

    default:
        return state;
    }

};

and my action looks like this:

export const addMovieToList = (movie) => {

    return {
        type: 'MOVIE_ADDED_TO_LIST',
        movie
    };

}; 

And here is how I am mapping stateToProps.

function mapStateToProps(state, props) {

    return {

        WatchListEvents: state.watchList

    }

}

export default connect(mapStateToProps)(WatchList);

1 Answer 1

1
export default (state = [], action) => {

    switch(action.type) {

    case 'MOVIE_ADDED_TO_LIST':
        return [
            ...state,
            movie.event
        ];

    default:
        return state;
    }

};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.