I am trying to set the state of a component prior to making the API call. The problem is the API call being called first. Here is what I have.
onPress={() => {
setMeal('dinner');
addToLogButtonPressed();
}}
When I press the button addToLogButtonPressed();
calls first which causes an error.
How to I call setMeal
before addToLogButtonPressed
?
I think you can use useEffect to do that