Skip to content

Commit

Permalink
chore(docs): adds docs for useCurrentUser hook (#4919)
Browse files Browse the repository at this point in the history
* chore(docs): adds docs for useCurrentUser hook

* docs(core): update docs for useCurrentUser hook

Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>

---------

Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>
  • Loading branch information
binoy14 and rexxars committed Sep 13, 2023
1 parent 0f52cfc commit 85719b7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/sanity/src/core/store/user/hooks.ts
Expand Up @@ -22,7 +22,22 @@ export function useUser(userId: string): LoadingTuple<User | null | undefined> {
return useUserViaUserStore(useMemo(() => [userStore, userId], [userId, userStore]))
}

/** @internal */
/**
* Retrieves information about the currently authenticated user.
*
* @returns The current user or null if not available.
*
* @public
*
* @example
* ```ts
* const currentUser = useCurrentUser()
*
* if (currentUser) {
* console.log('Logged in as', currentUser.name)
* }
* ```
*/
export function useCurrentUser(): CurrentUser | null {
const {currentUser} = useSource()
return currentUser
Expand Down

2 comments on commit 85719b7

@vercel
Copy link

@vercel vercel bot commented on 85719b7 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 85719b7 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.