Johnsoct
4/5/2018 - 3:27 PM

Return array with one updated index

Using ES6's spread operator, this is an easy way to update a single index within an array and return the "new" array.

return [
    ...state.slice(0, index),
    {
    	...state[index], likes: state[index].likes + 1
    },
    ...state.slice(index + 1),
]