I’ve been reading Redux documentation and I saw this piece of code, which returns state using spread operator. I don’t understand its use in this context. What exactly does it do? What does ...state
mean (is)?
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{
text: action.text,
completed: false
}
]
case 'COMPLETE_TODO':
return [
...state.slice(0, action.index),
Object.assign({}, state[action.index], {
completed: true
}),
...state.slice(action.index + 1)
]
default:
return state
}
}