mutation

Replace array item with another one without mutating state

寵の児 提交于 2019-11-29 17:02:53
问题 This is how example of my state looks: const INITIAL_STATE = { contents: [ {}, {}, {}, etc.. ], meta: {} } I need to be able and somehow replace an item inside contents array knowing its index, I have tried: return { ...state, contents: [ ...state.contents[action.meta.index], { 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,