How to update nested redux state -


i have following structure

lookups --> object lookups.categories --> array of category objects lookups.timezones --> array of timezone objects 

i add new object, lookup object has lookup_type property. either 'category' or 'timezone'. depending on lookup_type, newly added object has added either categories or timezones object. how achieved? structure of lookups object

lookups: {categories:[{obj1}, {obj2}...], timezones:[{obj1}, {obj2}, {obj3}...]} 

you can use spread on nested object or array too:

return {   ...state,   [action.lookuptype]: [     ...state[action.lookuptype],     action.value,   ] }; 

that add new item categories or timezone, if want replace value or insert @ index etc should construct new array how want above return , pass instead. note array spread es7.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -