Immutable.js DeleteIn Not Working
I have been trying to solve this problem, but there is probably something of Immutable.js that I don't catch. I hope somebody can help me to understand. I have a test like this: i
Solution 1:
This should work:
export function removeAtListOfMembers(state) {
const members = state.get('members');
const removing = state.get('removing');
return state
.deleteIn(['members', String(removing) ])
.remove('removing');
}
Your code has two issues:
deleteIntakes a singlekeyPathargument, which in your case is[ 'members' ]. The second argument (removing) is ignored, so the result is that the entiremembersmap is deleted; instead,removingshould become part of the key path.removingis aNumber, but because you're creating aMapfrom a JS object, its keys will beString's (this is mentioned in the documentation as well):Keep in mind, when using JS objects to construct Immutable Maps, that JavaScript Object properties are always strings
So you need to convert removing to a String when passing it to deleteIn.
Post a Comment for "Immutable.js DeleteIn Not Working"