Edit

The edit functionality is very similar to create product and the EditProduct form component is also only accessible by verified sellers at /seller/:shopId/:productId/edit.

mern-marketplace/client/MainRouter.js:

<PrivateRoute path="/seller/:shopId/:productId/edit" component={EditProduct}/>

The EditProduct component contains the same form as NewProduct with populated values of the product retrieved using the read product API, and it uses a fetch method to send multipart form data with a PUT request to the edit product API in the backend at /api/products/by/:shopId.

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

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

The update ...

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.