1

So I am having trouble updating in the reducer with Immutable.js.

So lets say I have a an initial state in my reducer as so:

Immutable.Map(action.someData)

where someData is a JSON, I received from a server:

someData: {
    contactInfo: {phoneNumber: 123-1253}
    address: 101 e street
    family: { 
        husband: "Bob"
        wife: "Sally"
    }
}

If I wanted to update the family.husband, how would I go on to do it?

since someData is just a regular object, does this not allow me to use setIn method?

1 Answer 1

2

Looking into Immutable documentation, I think the correct way is to create immutable structures on all levels, that is:

Immutable.fromJS(action.someData)

then you will be able to use setIn.

If you keep the internal objects as plain javascript objects, they are still mutable.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the response. I am able to use getIn to access the value, but using setIn , I do not see any changes. I have this, as you've suggested Immutable.fromJS(action.someData) state.setIn([family, husband], 'John'), where state is the what I created for the Immutable map is this correct?
never mind, I found a bug and was able to fix it. I will mark it as correct answer. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.