This is my code:
function login(event) {
event.preventDefault();
console.log("*1*");
let formData = new FormData(event.target);
ApiRequest.axiosInstance({ method: "post", url: "/login/login.php", data: formData, headers: {} })
.then(res => {
console.log("*2*");
getUsersProduct;
console.log("*3*");
})
.catch((err) => {
console.error(err);
console.log("*4*");
})
.then(() => {
console.log("Login Finished");
console.log("*5*");
});
}
}
function getUsersProduct() {
console.log("*6*");
ApiRequest.axiosInstance({ method: "post", url: "/login/getUsersProduct.php", data: formData, headers: { "Content-Type": "multipart/form-data" } })
.then(res ....
console.log("*7*");
}
I didnt write down the whole code but my problem is it show me console output: 1 2 6 3 instead of 1 2 6 7 3
the function getUsersProduct has to finish first. How do I do this in my react code? Do I have to use async and await?