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
From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Overview and fetch API example8m
-
(Locked)
Axios installation and example6m 21s
-
(Locked)
Setting up Axios client8m 32s
-
(Locked)
Setting up Axios interceptors3m 37s
-
(Locked)
Comparison and summary3m
-
(Locked)
GET requests5m 1s
-
(Locked)
Deep understanding of fetch and Axios7m 13s
-
(Locked)
Loading and error UI patterns4m 16s
-
(Locked)
Enhancing the loading state with loader component3m 16s
-
(Locked)
Enhancing the error state with error component3m 35s
-
(Locked)
Skeleton loader6m 23s
-
(Locked)
Summary54s
-
(Locked)
Why useEffect matters: Overview2m 25s
-
(Locked)
Correct ways of dependency management5m 4s
-
(Locked)
Handling race conditions12m 36s
-
(Locked)
Mistakes to avoid: Summary2m 7s
-
(Locked)
CRUD operations: Introduction4m 45s
-
(Locked)
Project setup overview3m 19s
-
(Locked)
Fetching products: GET3m 14s
-
(Locked)
Adding a product: POST4m 26s
-
(Locked)
Updating a product: PUT5m 35s
-
(Locked)
Deleting a product: DELETE2m 8s
-
(Locked)
Combining everything as an SPA5m 55s
-
(Locked)
Common mistakes: Practices and summary4m 47s
-
(Locked)
Advanced API integration: RTK and TanStack recap3m 8s
-
(Locked)
Recap: UseQuery fetching data using TanStack Query3m 55s
-
(Locked)
Recap: Mutation and optimistic updates with TanStack Query2m 18s
-
(Locked)
Key benefits and summary2m 27s
-
(Locked)
Project overview and setup4m 57s
-
(Locked)
API client setup10m 8s
-
(Locked)
Fetching all posts7m 45s
-
(Locked)
Creating a new post6m 10s
-
(Locked)
Updating a post5m 30s
-
(Locked)
Deleting a post7m 43s
-
(Locked)