I am struggling to get my head around async/await.
I have the following code which calls:
submitHandler()which posts a form's inputs to Google sheets
const scriptURL =
'GOOGLE SCRIPT URL'
const form = document.forms.emailform
fetch(scriptURL, { method: 'POST', body: new FormData(form) })
.then(response => {
console.log('Success!', response)
setFormSuccess(1)
})
.catch(error => {
console.error('Error!', error.message)
setFormSuccess(2)
})
}
childRef.current.upload()which posts a file to S3...
but I need to wait for the results from both these functions before I call another function to open a modal and pass in the results of these two functions.
Can anybody help me please?
Many Thanks
async function onSubmit() {
setTimeout(() => {
submitHandler()
childRef.current.upload()
}, 1000)
}
//I want to wait for onSubmit to complete and then call another function which sets state and then launches a modal
EDIT: I for got to mention in the original question that I have tried await in all of the functions I call, but none of them work