-
-
Notifications
You must be signed in to change notification settings - Fork 867
Description
🐛 Bug Report
This may be a result of me doing things incorrectly, but I am working on a project using redux-immer to have immer used on all of my redux reducers. I wrote the following snippet:
myArray: string[];
...
case ACTION_TYPE.REMOVE_THING:
const idx = state.myArray.indexOf(action.item);
if (idx >= 0)
delete state.myArray[idx];
state.myArray should be [] after this, but instead it is [empty] and state.myArray.length === 1
Here is a screenshot of dev inspector
Is this the correct way to remove an item from an array? I rewrote my code to use a .filter() statement instead, and that works as expected.
To Reproduce
I am not 100% sure, but I believe trying to delete the only item in an array will always cause this behavior, however it might need to be a nested property.
For my case: Use redux-immer's combineReducers on a redux proejct. In one of the stores, create an array property, create an action+reducer that tries to delete an item from the array described above.
Expected behavior
To return an empty array object, [], with .length===0, not this
Link to repro (highly encouraged)
It's a private repro, but if needed, I can invite as a collaborator to view behavior first-hand if unable to reproduce.
Environment
Relevant packages:
"immer": "^3.2.0",
"preact": "^10.0.0-rc.0",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-immer": "^1.0.3",
"redux-thunk": "^2.3.0"