From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Requests file - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Requests file
So we have this FetchProperties in both the HomeProperties component and the Properties page. So I think we should put that somewhere else. So I'm going to grab this from HomeProperties, the FetchProperties function, and cut that. And then let's create in the root a folder called Utils. I mean, you could really put this anywhere, but I'm going to put it in Utils. And I'm going to call this file requests.js. Now, I'm not going to put every request that I make in this file. You could do that if you want. You could create some kind of API service. But for the most part, we're going to be just fetching from the components. But for the basic get all properties or get a single property, we'll put those in here because we're going to use those in multiple places around the project. All right. So let's paste that in here. And then let's export that at the bottom. So we're going to export, not as default, because we're going to put some other stuff in here as well. But let's export Fetch…
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)
Create MongoDB database8m 44s
-
(Locked)
MongoDB Compass and importing data4m 36s
-
(Locked)
Database connection and Mongoose6m 31s
-
(Locked)
Your first API route6m 5s
-
(Locked)
Property and user models12m 30s
-
(Locked)
Fetch data using server component9m 48s
-
(Locked)
Requests file4m 25s
-
(Locked)
Fetch single property10m 51s
-
(Locked)
Single property page11m 54s
-
(Locked)
Property details component15m 34s
-
(Locked)
Spinner component2m 37s
-
(Locked)
-
-
-
-
-
-
-