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.
Fetch results from API - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Fetch results from API
So we have our search endpoint. We were able to test that out directly. Now we need to make it so that when we go to the search results page, it actually, first of all, shows up because we haven't created it yet. And then we have to hit that endpoint that we created in the last video so we can fetch the properties and show them. So let's go into the, you can close up the API folder. And we're going to go into properties, so app and then properties. And then let's create a new folder called search-results. And then in there, we'll create a page.jsx. And let's say rafce. We're going to call this search results page. And that should show up here. Good. And then let's just start to bring in what we need. This is going to be use client. And we're going to import the use state and use effect hooks from React. And then what else do we need? We want to get the params right here, right? So in the last video, we created the API route. And we were able to get it from the API request that we're…
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.