Hi I am running two API's inside async function in react JS. Sometimes It is working fine but sometimes second API is running before first is finished. Here is my code -
Interface A {
onSaveClick: (myData: DataInfo, hasDone: boolean) => void;
}
const onSaveClick = async (myData: DataInfo, hasDone: boolean):Promise<void> => {
await saveData(myData, hasDone); // first API
await getData("A", "B", "C"); // second API
};
Sometimes it works fine but sometimes not. I don't want to use setTimeout. What am I doing wrong ?
saveDataandgetDataare defined. Also, this question doesn't appear to be related to reactjs.