There is initially such a construction
{ books: [ { id: '200', author: '4124', name: '412', imgUrl: 'data:image/jpeg;base64' } ] } We need to somehow go through the array of objects in the books property, and replace the object in the array with the one that passes by id , and then return the new object with the books property in which we replaced the object without changing the old object.
Those. the total should return a new object
{ books: [ { id: '200', author: 'new author', name: 'new name', imgUrl: 'some img' } ] } We return a new object with the books property, but I don’t know how to replace the object and add to the array.
const changedItem = action.book return Object.assign({}, state, { books: state.books.map(item => item.id === changedItem.id ? changedItem : item) });