I'm trying to understand the purpose of the spread operator. From what I understand from the documentation, the spread syntax copies over the existing object and gets overridden when a new object is passed in. in the code below:
export default function reducer(state={
user: [],
fetching: false,
fetched: false,
error: null,
}, action) {
switch (action.type) {
case "FETCH_USER_FULFILLED": {
return {
...state,
fetching: false,
fetched: true,
user: action.payload,
}
}
}
return state
}
So if my understanding is correct this means that '...state' returns the object:
{
user: [],
fetching: false,
fetched: false,
error: null,
}
So if i substitute '...state' with the object i should get this:
{
user: [],
fetching: false,
fetched: false,
error: null,
fetching: false,
fetched: false,
user: user.payload
}
Wouldn't it be redundant?