I have order reducer, which has many states.
const initialState = {
channel: null,
order: {},
fetching:true,
menu: [],
categories: [],
subcategories: [],
currentCategoryId: 1,
currentSubcategoryId: 5,
currentMenu: [],
};
What I want to filter is menu. menu is array of state which has objects of menu_item I have currentCategoryId and currentSubcategoryId. What I want to do with these states is that by using currentCategoryId and currentSubcategoryId to filter menu and put filtered states to currentMenu.
case Constants.ORDER_CHANNEL_CONNECTED:
return
{...state,currentMenu: action.menu.map((menu) => {
if(state.currentCategoryId == menu.category_id){
return menu;
}
else return false;}}
So to do that I made code like above. Even though it returns some filtered value, it shows same number of array with many false values. I want to find other approaches to do that..
How can I do this?
Thanks in advance.