Short question is: what does the line
return { ...state, all: action.payload.data };
do? (particularly with the all:
part).
If you don't use ES6, and state
has
- 2 properties like below
- 10 properties instead of 2
- unknown number of properties
then how would it be written?
Details: it is part of React / Redux. In a reducer function, given a previous state and action, it does:
const INITIAL_STATE = {
all: [],
post: null
};
export default function(state = INITIAL_STATE, action) {
switch(action.type) {
case FETCH_POSTS:
return { ...state, all: action.payload.data };
default:
return state;
}
}