我有一個減速,那首先得書數組對象的列表沒有書副本count屬性,而且比每本書得到它的拷貝數在終極版減速器如何更新數組對象內1個屬性
const bookList= (state = [], action) => {
switch (action.type) {
case 'BOOKS_REQUEST_SUCCEEDED':
return Object.assign({}, state, action.payload);
case 'BOOKS_COUNT_REQUEST_SUCCEEDED':
return updateBookCopiesCount(state, action);
default:
return state
}
}
const updateBookCopiesCount = (state, action) => {
const newState = state.map((book) => { // updating only the book copies count
if (book.Id === action.payload.Id) {
return { ...book,
copiesCount: action.payload.copiesCount
};
}
return book;
});
return newState;
}
我的問題是,什麼是正確的終極版的做法: 應該每次我整個數組複製爲每個copiesCount更新所有對象,還是確定只複製,將其與新的屬性修改的對象
在此先感謝