Replace array item with another one without mutating state. Use Splice mutate the array you need to use Slice . And you also need to concat the sliced piece.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | return Object.assign({}, state, { contents: state.contents.slice(0,action.meta.index) .concat([{ content_type: 7, content_body: { album_artwork_url: action.payload.data.album.images[1].url, preview_url: action.payload.data.preview_url, title: action.payload.data.name, subtitle: action.payload.data.artists[0].name, spotify_link: action.payload.data.external_urls.spotify } }]) .concat(state.contents.slice(action.meta.index + 1)) } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.