I have a reducer, that first gets a list of books array objects without the book copies count property, and than for each book it get the number of copies
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;
}
my question is, what is the right redux approach: should I copy each time the entire array with all the objects for each copiesCount update, or is it ok to copy only the object that was modified with the new property
Thanks in advance