Home > Software engineering >  Status does not change when I delete data from here
Status does not change when I delete data from here

Time:05-01

const [products, setProducts] = useMangeProduct([]);
const handelDeleteProduct = id => {
        const url = `https://fierce-everglades-14403.herokuapp.com/product/${id}`;
        fetch(url, {
            method: 'DELETE',
        }).then(res => res.json())
            .then(data => {
                console.log(data);
                if (data?.acknowledged === true) {
                    const restProducts = products.filter(product => product._id !== id)
                    setProducts(restProducts);
                    toast.error('Product Delete successfully')
                }
            })
    }

** state Change** data deleted but state not change. if I reload the page so I can see my data is deleted. But when I click on the delete button, there is no change.

CodePudding user response:

You mean that way?

let sure = confirm('Do you want to delete your constumer?');
if (sure) {
    // code to send fetch to your server
}

CodePudding user response:

I have used something like this for Anchor Link. Hope that helps.

<a href="#" onclick="if (confirm('Do you really want to delete this User?')) {return true;}else{event.stopPropagation(); event.preventDefault();};"> Delete User </a>
  • Related