I am having trouble wrapping my head around the way a redux-reducer works in JavaScript.
Here is the example I am working with:
const intitialState = {
profile: null,
profiles: [],
repos: [],
loading: true,
error: {},
};
export default function (state = intitialState, action) {
const { type, payload } = action;
switch (type) {
case GET_PROFILE:
return {
...state,
profile: payload,
loading: false,
};
case PROFILE_ERROR:
return {
...state,
error: payload,
loading: false,
};
default:
return state;
}
}
Which of these assumptions is correct, if either, about this reducer?
A) When GET_PROFILE is triggered, it returns '...state' as the initial state so that the redux dev tools can compare states.
B) When GET_PROFILE is triggered, it is really just filling in the values into the object that I didn't explicitly list. As in the return really looks like this:
return {
profiles: profiles,
repos: repos,
error: error,
profile: payload,
loading: false,
};
And if A or B is true, then what happens if I do not return ...state as the first one, will this mess up the other objects?
Edit: And where exactly does it return to?