0

I have an immutable state in React, where I have an map containing list elements.

My getIn function works correctly, e.g.:

console.log(this.state.settings.getIn(["airlines"])[index].checked);

But I want to update this value with the reverse.

Reading the docs of immutable JS, it should be something like this, but due to my index key I can't get it to work, since my update val should be within the ().

What I currently have is something like this:

this.state.settings.updateIn((["airlines"])[index].checked, val => !val);

Any help is appreciated!

4

1 回答 1

0

You need to pass path to updated property as array. Demo.

this.state.settings.updateIn(['airlines', index, 'checked'], val => !val);

BTW The same works with getIn. You can do

console.log(this.state.settings.getIn(['airlines', index, 'checked']));
于 2016-07-20T12:53:51.487 回答