Skip to content

Instantly share code, notes, and snippets.

@olegkalyta
Created September 25, 2018 14:59
Show Gist options
  • Save olegkalyta/4225e96162e887d54f7cb24e4c3a8531 to your computer and use it in GitHub Desktop.
Save olegkalyta/4225e96162e887d54f7cb24e4c3a8531 to your computer and use it in GitHub Desktop.
const filterReducer = handleActions(
{
[toggleSelectedCategory]: (state, { payload: { id, name } }) => {
const categoryExists = state.selectedCategories.find(sc => sc.id === id)
if (categoryExists) {
return {
...state,
selectedCategories: state.selectedCategories.filter(sc => sc.id !== id),
}
}
return {
...state,
selectedCategories: [{ id, name }, ...state.selectedCategories],
}
},
},
initialState.selectedCategories
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment