13

I have a immutable list object, within a Map object, as follows:

let initialState = Immutable.fromJS({});
state = initialState;
state = state.set("myList", Immutable.List());

How do I append a value to "myList", thereby updating state?

Baz
  • 12,713
  • 38
  • 145
  • 268

2 Answers2

22

You can use update() method.

const initialState = Immutable.fromJS({});
const state = initialState.set('myList', Immutable.List()); 

const updatedState = state.update('myList', myList => myList.push('some value'));
caspg
  • 508
  • 5
  • 8
4
emails = List(new Array<string>());
defaultValues = ['gold@gmail.com', 'saphire@gmail.com'];
this.emails = this.emails.push(...this.defaultValues);

This is for typescript .

I.Tyger
  • 715
  • 1
  • 8
  • 19