0
我有一個狀態對象,看起來像這樣:終極版推到一個嵌套的數組沒有突變狀態
PlaylistDictionary: {
someId: {
pages: [] // trying to push something to this array here
},
someId2: {
pages: [] // trying to push something to this array here
}, etc
}
我試圖更新「頁面」數組,但我不斷收到一個錯誤說我」 m突變的狀態..我不明白,因爲如果我用Object.assign複製狀態對象...我如何改變狀態?感謝您的幫助
case types.ADD_PAGE_TO_PLAYLIST: {
let playlistDictCopy = Object.assign({}, state.playlistDict);
if (!playlistDictCopy[ action.playlistId ].hasOwnProperty('pages')) {
playlistDictCopy[ action.playlistId ].pages = [];
}
playlistDictCopy[ action.playlistId ].pages.push(action.pageId);
return Object.assign({}, state, { playlistDict: playlistDictCopy });
}
現在就試試看ty說明 – user1189352