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.

Creating a new post

Creating a new post

Welcome back. In this video, we'll set up a new post in our react application. For creating a new post, we need to have a hook which is going to be use create post hook. This hook will call query client and this time we are going to use the use mutation hook to creating a new post. Because this is a mutation for adding a new item and changing the data, then we have to use the use mutation hook. Similarly, we are also going to need a component which can have the form for getting the items for the field inputs for the new post and we can call the use create post hook and based on that we can create a new post. So let's get to action. In our application, in the components folder, we are going to have a new component, we'll call it postForm.tsx. Let's have the components logic pasted here. This useCreatePost hook which we have to create and we are going to create it in a while. We are going to get a mutate function and a spending function. The spending basically tells that the API call is…

Contents