As far as I can tell, my answer for the 2nd question is correct. But I get a 'red X" for the question, without any error message indicating what’s actually wrong with my answer.
Can you post your code? It worked fine for me when I took the course.
Sure. this is what I have for the “sliceOptions” object:
const sliceOptions = {
name: "allRecipes",
initialState: {
recipes: [],
isLoading: false,
hasError: false
},
reducers: {},
extraReducers: {
[loadRecipes.pending]: (state, action) => {
state.isLoading = true;
state.hasError = false;
},
[loadRecipes.fulfilled]: (state, action) => {
state.recipes.push(action.payload);
state.isLoading = false;
state.hasError = false;
},
[loadRecipes.rejected]: (state, action) => {
state.isLoading = false;
state.hasError = true;
}
}
}
action.payload
is already an array. You’re pushing an array to an array here, so []
would become [[element1, element2, element3]]
You need to replace the existing array entirely with the new array.
Click if that wasn't clear
state.recipes = action.payload;
Yep, that was the issue, thanks for responding!