kobe kobe - 1 year ago 127
React JSX Question

Redux reducer not updating state object

I have the following code, and I am trying to update the state but it is not working.

import Immutable from 'immutable';
import _un from 'underscore';
import { List, Map } from 'immutable';

const defaultState = Map({
deparments: List(),

I am using set but when I console before return it just prints the original object. What am I doing wrong?

switch(action.type) {

//console.log("-- api success handler--");

var depts = getGalleryParsedData(action.res.data);
var products = getProducts(action.res.data);
var breadcrumb = getBreadcrumbs(action.res.data);

state.set('isFetching', true);
state.set('deparments', List(depts))
state.set('products', List(products))
//state.set('breadcrumb', List(breadcrumb))

return state;

Answer Source

Immutable.js does not mutate your state, it returns a mutated copy of the original object.

state = state.set('isFetching', true);
state = state.set('deparments', List(depts));
state = state.set('products', List(products));


state = state
  .set('isFetching', true)
  .set('deparments', List(depts))
  .set('products', List(products));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download