I am using react, with redux for state management. In my UI I have a button which when clicked it calls a function and that function internally calls 2 redux actions that perform the specific task. The problem is my function when I make a call after a click of the button it immediately calls both the functions.
This is my on button click function
const handleDecrement = (productId) => {
props.minusQuantity(productId, props.guestIdData); // call make to redux action to perform API action
props.quantityData.forEach((item) => {
if (item.productQuantity < 1) { // value of state. Which is instantly changed
props.removeWholeItem(productId); // Another API call to redux action
}
});
};
I want to call this function first
props.minusQuantity(productId, props.guestIdData);
and thnen later the following code
props.quantityData.forEach((item) => {
if (item.productQuantity < 1) { // value of state. Which is instantly changed
props.removeWholeItem(productId); // Another API call to redux action
}
});
redux-thunkfor async actions