Ich habe einen Druckminderer, dass zuerst ohne das Buch eine Liste der Bücher Array Objekte bekommt Kopien Eigentum zählen, und als es die Anzahl der Kopien für jedes Buch erhaltenIn redux Minderer wie 1 Objekt innerhalb Array-Objekt aktualisieren
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;
}
meine Frage ist, was ist der richtige redux Ansatz ist: soll ich jedes Mal das gesamte Array mit allen Objekten für jedes copiesCount Update zu kopieren, oder ist es in Ordnung, nur das Objekt zu kopieren, die mit der neuen Eigenschaft geändert wurden
Vielen Dank im Voraus