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…

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

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

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