javascript - Redux reducer not updating state object -
i have following code, , trying update state not working.
import immutable 'immutable'; import _un 'underscore'; import { list, map } 'immutable'; const defaultstate = map({ isfetching:true, deparments: list(), products:list(), breadcrumb:list() })
i using set when console before return prints original object. doing wrong?
switch(action.type) { case 'get_gallery_data': //console.log("-- api success handler--"); //console.log(action); 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)) console.log("---state----"); console.log(state); return state;
immutable.js
not mutate state, returns mutated copy of original object.
state = state.set('isfetching', true); state = state.set('deparments', list(depts)); state = state.set('products', list(products));
or
state = state .set('isfetching', true) .set('deparments', list(depts)) .set('products', list(products));
Comments
Post a Comment