我正在寻找有关如何在删除之前向此功能添加提交按钮的答案。我的部分代码:
// func
const deleteData = id => {
setEditing(false);
firebase
.firestore()
.collection("users")
.doc(id)
.delete();
};
------------------
// and the button without submit option
<button onClick={() => props.deleteData(props.item.id)} />
为了确保一个接一个的函数调用,您需要异步编写它们。
这可以通过async/await
完成。
尝试此代码段!
// this will be your submit function
const yourSubmitFunction = () => {
return new Promise(resolve => {
// simulate waiting for a submit
setTimeout(() => {
// resolve after submission
resolve('submitted!')
}, 2000)
})
};
// asynchronous function
const asyncCall = async () => {
console.log('waiting for submit...')
const result = await yourSubmitFunction()
console.log(result)
// .. now you can call your delete function
}
// click and call your asynchronous function
asyncCall()