abhigk
August 29, 2021, 5:39am
1
I was following this Redux tutorial
I wanted to replace the array of objects in the state with a new array of objects in the extra reducer.
Here is my code
[deleteTodosAsync.fulfilled]: (state, action) => {
state.todos = action.payload.todo;
}
I am getting error that Immer only supports setting array indices and the ‘length’ property
jenovs
August 29, 2021, 5:54am
2
My guess would be that action.payload.todo
is not an array (and if it is, you should think about naming). If I’m correct, then you’re trying to replace todos
array with a single todo
which is causing the error.
abhigk
August 29, 2021, 1:26pm
3
I was able to solve the issue by simply returning the new array and it updated the state
[deleteTodosAsync.fulfilled]: (state, action) => {
return action.payload.todo;
}
1 Like
system
Closed
February 28, 2022, 1:27am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.