Issue
I need to detect if the axios request (with async/await) is in loading phase. Because, I need to disable a button if the request is loading.
const response = await API.get("/url", options);
Now, I need to disable a certain button if this request is in loading phase. But, I'm stuck on how to solve this issue.
Solution
setState(true) //to initate loading
const response = await API.get("/url", options);
setState(false) //to turn off loading
try{
setState(true) //to initate loading
const response = await API.get("/url", options);
}
catch(err){}
finally{
setState(false) //to turn off loading
}
Answered By - Mohammed Shahed
Answer Checked By - - Pedro (ReactFix Volunteer)