August 2017
Beginner
374 pages
10h 41m
English
Next, we will handle the EDIT_POST action type:
case EDIT_POST: { const { type, id, ...newPost } = action
This time, we will pull out the type and id properties, because we will need the id later, and it should not be part of the post object.
We use the Array.prototype.map() function to return a new state array. If you do not know this function, it has the following signature:
const newArr = arr.map( (elem, index) => { ... })
As you can see, map() accepts a callback function. The map function executes the callback function on each element and creates a new array from the return values of that callback function. Basically, map lets us apply a function to all elements ...
Read now
Unlock full access