Add value to list

I have an immutable list object in an object Mapas follows:

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

How to add value to "myList", thereby updating state?

+4
source share
1 answer

You can use the update () method .

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

const updatedState = state.update('myList', myList => myList.push('some value'));
+10
source

Source: https://habr.com/ru/post/1660689/


All Articles