I am working on a form submit and want to get the tokens on submit, because if I get them on page load load they might expire before use.
function handleSubmit(e) {
e.preventDefault();
async function getTokens() {
return axios
.get("example.com/get-token/306/")
.then((response) => {
return response.data;
});
}
getTokens().then((data) => {
async function submitForm() {
const formData = new FormData();
formData.append("token", data.message);
formData.append("session", data.session);
formData.append("email", email.current.value);
const res = await axios.post(
"https://example.com/submit/306/",
formData,
{
headers: { "Content-Type": "multipart/form-data" },
}
);
}
submitForm();
});
}
Will this significantly decrease performance? The other method I tried is saving the tokens with setState on page load, but as I said this risks them expiring before use.