Delete

The DeleteProduct component is added to the MyProducts component for each product in the list, as discussed earlier. It takes the product object, shopID, and a loadProducts method as a prop from MyProducts. The component is similar to DeleteShop, and when the delete intent is confirmed by the user, it calls the fetch method for delete, which makes the DELETE request to the server at /api/product/:shopId/:productId.

mern-marketplace/server/routes/product.routes.js:

router.route('/api/product/:shopId/:productId')      .delete(authCtrl.requireSignin, shopCtrl.isOwner, productCtrl.remove)

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.