I'm fairly new to react and redux. I'm working on a reducer and running into compilation errors when trying to use the spread operator.
export default function chaptersReducer(
state = { chapters: {}, isFetching: false, error: false },
action = {},
) {
switch (action.type) {
case REQUEST:
return { ...state, isFetching: true, error: false };
case SUCCESS:
return {
...state,
chapters: {
...state.chapters,
action.payload
},
isFetching: false
};
case FAILURE:
return { ...state, isFetching: false, error: true };
default:
return state;
}
}
The specific error I'm getting is this. (inside the SUCCESS case)
Syntax error: Unexpected token, expected , (27:44)
> 27 | chapters: {...state.chapters, action.payload},
| ^
Maybe I'm missing something extremely obvious, but can someone help me figure out what's going on?
EDIT: I'm using create-react-app, redux, and react-redux
...state.chapters? Should it not just be...stateorstate.chapters. Why are you using a spread operator onchapters?{ mangaId: [{ chapterObjects }] }. My intention was if chapters is empty, add the payload, if mangaIds conflict, overwrite the old data.Perhaps I'm misunderstanding how to do that correctly?