'Can't stop the asynchronous flow
I have the following function:
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const email = (event.target as any).email.value;
const score = (event.target as any).score.value;
if(!validateEmail(email)){
return;
}
const config: AxiosRequestConfig = {
baseURL: BASE_URL,
method: 'PUT',
url: '/scores',
data: {
email: email,
movieId: movieId,
score: score
}
}
axios(await config);
navigate("/");
}
I want "navigate("/")" to happen only when axios(await config) requisition finishes. I'm trying to use async await but I can't get it to work. Any suggestions? I'm not used to React so please be descriptive.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
