From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Deleting a post

Deleting a post

Hello and welcome back. In this video, we'll have the code for deleting a post using danstack query. You know the drill. The idea is the same. We have to create a hook which is going to call the query client and use mutation hook. The mutation function this time is going to be delete post and on mutate, we have to add update the existing data and delete in deleted item from that data. We also have to handle the error cases and the onSettled event which is going to settle our data by invalidating the queries. So let's get started. We don't need a component for this, rather we have to go in the post list component and uncomment the lines that we commented at the start. So we are going to need a hook, we also need the delete icon, we need this use delete post delete mutation variable as well. And we are also going to uncomment this button that we had. This button is going to ask for a confirmation on click and it is going to call the mutate function based on the id of the post. Then we…

Contents