reactjs - Update reducer A based on reducer B -


goal:

update favorite colors based on filters.

setting:

there 2 reducers: filters , colors.

export function filters(state = {   nored: false,   noblack: false, }, action) { ... })  export function colors(state = {   red: true,   black: true,   blue: true }, action) { ... }) 

i want update colors based on filters. can dispatch setfilter , setcolor @ same time, doesn't work because setcolor should happen after filters reduced completely. can think of combining filters , colors together, i'd keep them separated.

what's best way achieve goal? need following:

export function colors(state = [], action) {   switch (action.type) {     case constants.set_filter:       // assume can access filters reducer here       var filters = filtersreducer       var colors = applyfilters(state.colors, filters)       return colors     case constants.set_color:       return action.colors     default:       return state   } } 

or can dispatch action inside filters reducer, that's antipattern.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -