课程: React: Creating and Hosting a Full-Stack Site (2022)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Creating a custom auth hook

Creating a custom auth hook

- [Instructor] All right, so now that users can log into our application through the login page. The next thing that we're going to need to do is modify our article page so that it can adjust based on whether a user is logged in or not. Now, to give you an idea of what this is going to look like, inside our article page, remember that we're displaying both this Upvote section which allows a user to up vote an article, and we're also displaying this AddCommentForm. Now, we're only going to want to display both of those if the user is logged in. Because we're only going to want users to be able to up vote articles once. And we're only going to want users to be able to add comments if they're logged in. All right, so basically what we're going to need in this article page component, is a way to know at any given moment whether the user is logged in or not. And that's where this useUser custom hook comes in. So what this…

内容