Чтобы гарантировать выполнение одного вызова функции за другим, вы хотите написать их асинхронно.
Это можно сделать с помощью 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()