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

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…

Contents