[英]How can i update my component after delete methods in React?
I use Sweetalert2 and react(tsx) and i don't know how to refresh my item list after delete methods.我使用 Sweetalert2 和 react(tsx),我不知道如何在删除方法后刷新我的项目列表。
Here is the code (i have a button that use this functions):这是代码(我有一个使用此功能的按钮):
function DeleteCard(item: DataItem){
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
const response = await Api.delete('api/stuff/${item.Id}')
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
}).then(function(){
window.location.reload(); // this is page reload, it is woking but not a good solutions
})
}
I tried window.location.reload();, but not a good solution.我尝试了 window.location.reload();,但不是一个好的解决方案。
If you receive your items list from an api
, instead of window.location.reload()
, fetch the item list again.如果您从
api
而不是window.location.reload()
收到项目列表,请再次获取项目列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.