When i am on the menu page the user can check menu items to add them to cart and then it adds the selected items to cart and if cart.selecteditems.length > 0 the user can open a cart modal and can also increase quantity or decrease or remove the item from the modal. But when the user remove the item and closes the modal the checkbox of menuitem which was removed will be still checked the i need to fetch the menu again so that the page could re render and only added items should be checked Check Box Code
const cart = useSelector(state => state.cart)
const checkedAlreadyAdded = (id) => {
let alreadyExist = cart.selectedItems.findIndex((obj)=> obj.itemId == id) i
if(alreadyExist < 0){
return false
}else{
return true
}
}
<BouncyCheckbox
onPress={()=>addItemToCart(item)}
isChecked={checkedAlreadyAdded(item.id)}
/>
So the checkox is not updating its checked value when cart reducer make changes in selectedItems
Aucun commentaire:
Enregistrer un commentaire