javascript – React logic in JSX

I have some logic on my JSX for an element in a grid, if element is selected, then add to redux, if element is not selected then remove from redux…

is working ok, but I sense a bad smell…

<GridSelector
          items={items}
          onChange={(categoryId, isSelected) => {
            favorites(categoryId) = isSelected;
            const favsArraya = Object.values(onboarding.favoriteCategories);
            let index;

            if(isSelected){
              if (favsArraya.indexOf(categoryId) === -1){
                //doesnt exist, add it
                 favsArraya.push(categoryId)
              }
            }else{
              if (favsArraya.indexOf(categoryId) !== -1){
                // exists, delete it
                index = favsArraya.indexOf(categoryId);
                favsArraya.splice(index, 1);
              }
            }

            dispatchData({ (DATA_KEY.FAVORITE_CATEGORIES): favsArraya})

          }}
        />