SaroVin
SaroVin

Reputation: 1773

Update immutable state with dynamic key in redux

i have this initialState

const initialState = Immutable.fromJS({
  list: [],
  entities: {},
  something: {
    otherOne: false,
    otherTwo: false,
  },
});

and i want update the object something with a function like this:

[UPDATE_SOMETHING]: (state, { key }) => { // <== key is the name of the nested props
    return state.merge({
      filterBy: {[key]: !state.get('key')},
    });
  ),

but it does not work...how i can update the state dynamically?

Upvotes: 0

Views: 685

Answers (1)

Johnny Klironomos
Johnny Klironomos

Reputation: 214

[UPDATE_SOMETHING]: (state, {key}) => {
  const something = state.get('something').withMutations(s => {
    s.set(key, !s.get(key));
  });
  return state.set('something', something);
),

Something like that could help?

Upvotes: 2

Related Questions