【发布时间】:2020-11-14 22:01:42
【问题描述】:
我很难理解异步/等待。
我有以下代码调用:
-
submitHandler()将表单的输入发布到 Google 表格
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()将文件发布到 S3...
但我需要等待这两个函数的结果,然后再调用另一个函数打开模态并传入这两个函数的结果。
有人可以帮帮我吗?
非常感谢
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
编辑:我必须在原始问题中提到,我已经尝试在我调用的所有函数中等待,但它们都不起作用
【问题讨论】:
标签: javascript reactjs