I use Sweetalert2 and react(tsx) and i don't know how to refresh my item list after delete methods.
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.
If you receive your items list from an api
, instead of window.location.reload()
, fetch the item list again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.