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.

Updating a post

Updating a post

Hello and welcome back. In this video, we'll see how we can update a post. Just like the list and create cases, we have to create a new hook which is going to call a query client for invalidating queries and a mutation function which is going to mutate our post values. At this time, we are going to call the updatePost method instead of the createPost method. Then inside our component, we can simply have a useUpdatePost hook called and this is going to give us the mutate function, where we can pass on our data to mutate the updated value of a post. Let's see that in action. In the components folder, I'm going to have a new component updatePost.tsx. We can have the update logic of the component from here. As you can see, this is being called a, this is calling a updatePost hook that we are going to create and based on the form data, it is going to call the mutate function on that form data to actually call the API. There is one more API call happening in the update post form that is…

Contents