Skip to content Skip to sidebar Skip to footer

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:

  • deleteIn takes a single keyPath argument, which in your case is [ 'members' ]. The second argument (removing) is ignored, so the result is that the entire members map is deleted; instead, removing should become part of the key path.
  • removing is a Number, but because you're creating a Map from a JS object, its keys will be String'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"