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.
Bookmark button request - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Bookmark button request
OK, so we have the API route down. Now we want to add the functionality to this button so that if we click it, it either adds or removes the bookmark based on if it's there or not, if we already bookmarked it. So let's go to our bookmark button file here. And let's start off just bringing in what we need. It needs to be client side. So let's say use client because we are using some hooks here. And then we're going to import useState and useEffect from React. And we're also going to need to get the user. So yeah, let's import useSession. And what else do we need here? I guess just toast, because we do want to show. Basically, if they click it and they're not logged in, I want it to just show a toast saying you have to log in. And you can handle it a different way if you want. If you wanted to redirect them, or if you want to not even show the button if they're a guest, then you can handle it differently if you'd like. But I think this is what I want to do. So we want to import toast…
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)
Geocoding and Mapbox map16m 40s
-
(Locked)
Handle geocode error4m 4s
-
(Locked)
Property page cleanup6m 11s
-
(Locked)
Bookmark API route10m 28s
-
(Locked)
Bookmark button request8m 27s
-
(Locked)
Bookmark status and button toggle8m 54s
-
(Locked)
Saved properties page12m 17s
-
(Locked)
Share buttons10m 41s
-
(Locked)
-
-
-