0

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 ?

3
  • does this answer your question? Commented Feb 15, 2021 at 6:20
  • Nobody could answer your question without knowing how saveData and getData are defined. Also, this question doesn't appear to be related to reactjs. Commented Feb 15, 2021 at 6:34
  • need more information. share your saveDAta and getData code Commented Feb 15, 2021 at 6:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.