Baz
Baz

Reputation: 13123

Append value to List

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?

Upvotes: 13

Views: 20238

Answers (2)

I.Tyger
I.Tyger

Reputation: 805

emails = List(new Array<string>());
defaultValues = ['[email protected]', '[email protected]'];
this.emails = this.emails.push(...this.defaultValues);

This is for typescript .

Upvotes: 4

caspg
caspg

Reputation: 508

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'));

Upvotes: 22

Related Questions