user7597670
user7597670

Reputation:

spread operator on object react redux reducer

I am using redux with react.

I am updating the state which looks like this

state = {
    album: {
      name: 'Blood, Sugar, Sex, Magik'
      date: '1991',
      artist: 'RHCP'
   }
}

The relevant part of my reducer looks like this

case 'UPDATE_ALBUM_NAME_SUCCESS':

    return {
        ...state,
        album: {
            ...album,
            name: action.name,

        },

    };

action.name is 'Californication'

I want to just update the album name, however, my code is deleting all the other parts of album and just leaving the album.name. Can anyone advise how to do this properly?

Upvotes: 2

Views: 723

Answers (1)

Saad
Saad

Reputation: 53849

It should be ...state.album instead of ...album.

Upvotes: 4

Related Questions