[删除数据前提交按钮,reactjs

问题描述 投票:0回答:1

我正在寻找有关如何在删除之前向此功能添加提交按钮的答案。我的部分代码:

// 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)} />
reactjs firebase submit delete-row
1个回答
0
投票

为了确保一个接一个的函数调用,您需要异步编写它们。

这可以通过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()
© www.soinside.com 2019 - 2024. All rights reserved.