Home > Software design >  How to perform delete operation?
How to perform delete operation?

Time:09-02

For a production level web app, How anyone should perform a delete operation. Like if we have stored an array of products in global store(eg. Redux) on the client side. Now I perform a delete request to the backend to delete a product with id "001". Now should I get an updated list of products from the backend to display or I should just filter out the globally available state from the store?

I want to know the optimal way.

CodePudding user response:

Do Post Request with id to an api to delete. Get that id in backend delete it and then return updated records as result

CodePudding user response:

If you are building something like an e-commerce website you probably shouldn't store a copy of data about all your products in Redux.

If you store data about products on server you can use library like React Query to fetch it to display on client or mutate data stored on server(delete for example). React Query also has cashing for optimisation so you don't fetch data on every render. You can think of it as synchronization of your server and client state.

Redux is used to store client state like products in cart. You can use redux when you create data on client and manipulate it while it is stored in redux. Then you can send it to server when needed.

There is a great video about server state and client state with explanation and coding examples: https://www.youtube.com/watch?v=5-1LM2NySR0&t=891s&ab_channel=Theo-ping․gg

  • Related