Trying to learn redux & react, currently digesting this tutorial: https://thinkster.io/tutorials/learn-redux/
Now, i found this code snippet
const defaultState = { checked: false };
const reducer = function(state = defaultState, action) {
switch (action.type) {
case 'TOGGLE':
return { ...state, checked: !state.checked };
}
return state;
};
const store = createStore(reducer);
I need an explanation of this line: return { ...state, checked: !state.checked };
.
What does the ...state
do ? And is it a new feature of ECMA 2015 ??
Update
I don't think that this question is a duplicate of What does the three dots in react do?
The difference is that What does the three dots in react do? is about JSX spread attributes, while my question is about ECMAScript spread operator.
Well, not trying to be defensive but i think those two are different.
But somehow i get the answer for my question in What does the three dots in react do?
Thanks to mplungjan for pointing me to the latter question :)