case 'ADD_TODO': return [ ...state, { text: action.text, completed: false } ]
Asked
Active
Viewed 41 times
-3
-
Before you know what ...state does here in reducer, know what the `...` operator is. – Bhojendra Rauniyar Oct 01 '18 at 07:57
-
https://redux.js.org/recipes/usingobjectspreadoperator – Rohan Veer Oct 01 '18 at 07:58
-
Possible duplicate: https://stackoverflow.com/questions/31048953/what-do-these-three-dots-in-react-do – Bhojendra Rauniyar Oct 01 '18 at 07:58
-
`state` is one of the arguments given to your reducer function, which in this case gets copied (spread operator is `...`) and a new array is returned with 1 new item in it – Icepickle Oct 01 '18 at 07:59
-
@BhojendraRauniyar - And know that `...` [isn't an operator](https://stackoverflow.com/questions/44934828/is-foo-an-operator-or-syntax/44934830#44934830). – T.J. Crowder Oct 01 '18 at 07:59
-
@T.J.Crowder why is it called spread operator then? – Bhojendra Rauniyar Oct 01 '18 at 08:00
-
@BhojendraRauniyar - It isn't. – T.J. Crowder Oct 01 '18 at 08:02
-
1@T.J.Crowder Thanks. Until today, I was taking it as operator. – Bhojendra Rauniyar Oct 01 '18 at 08:02
1 Answers
0
This is the spread operator.
Documentation at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

Clément Bareth
- 80
- 5