August 2017
Beginner
374 pages
10h 41m
English
To update items, we can use Array.map to loop through all items, and then only edit certain items:
const updateItem = (state = [], action) => { const i = action.index const editedData = action.item return state.map((item, index) => { // we do not care about this item, skip if (index !== i) return item // we want to edit this item return { ...item, ...editedData } })}
Read now
Unlock full access