I have a cart state that holding array something like this:
[[{"Id": 123, "duration": 10, "name": "Burger", "price": 10, "qty": 1, "total": "10.00"}]]
and this is the reducers as showing I have added to more for increase and decrease the quantity:
const cartSlice = createSlice({
name: "cart",
initialState: [],
reducers: {
addItemToCart: (state, action) => {
state.push(action.payload);
},
removeItemFromCart: (state, action) => {
return state.filter(i => i[0].Id !== action.payload);
},
ADD_QUANTITY: (state, action) => {
// notsure how to handle here
},
SUB_QUANTITY: (state, action) => {
// notsure how to handle here
}
}
})
and in cart screen I am doing something like this:
<TouchableOpacity onPress={() => dispatch(ADD_QUANTITY(item[0].Id))} >
<Ionicons name="add-circle-outline" size={22} color="#cccccc" />
</TouchableOpacity>
so, once the button for add quantity pressed I want to update the cart state with new qty and new total price and same when decrease quantity, it may sound a very easy question but I am a beginner and i cant figure it out.