From the course: Next.js: Creating and Hosting a Full-Stack Site
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Loading individual products - React.js Tutorial
From the course: Next.js: Creating and Hosting a Full-Stack Site
Loading individual products
- [Instructor] All right, so now that we've done the product list page, the next page that we're going to add fetching functionality to is going to be the product detail page. Now, this page is going to be a little bit trickier, mostly just because we now have this route parameter to deal with, right? Telling us which product we should actually load. But as you'll see, it fits right in with the flow that we just learned about using that fetch function. So what we're going to do here is, first of all, we'll remove this products thing because we don't need that anymore, and then we're going to remove this products.find function because we don't need that either. What we're going to do is we're just going to say const product equals, and here's where we're going to use the fetch function again. We're going to say await fetch. And that reminds me we need to also add the async keyword to this component function. And then we're going to load from /api. I'll add the URL later. /api/products,…
Contents
-
-
-
-
-
-
(Locked)
Data loading basics in Next.js1m 13s
-
(Locked)
Loading data with Fetch5m 57s
-
(Locked)
Loading all products3m 39s
-
(Locked)
Loading individual products3m 9s
-
(Locked)
Loading shopping cart items6m 16s
-
(Locked)
Adding items to the cart10m 5s
-
(Locked)
Shopping cart improvements6m 2s
-
(Locked)
Challenge: Removing items from the cart1m 28s
-
(Locked)
Solution: Removing items from the cart5m 34s
-
(Locked)
-
-