Created
November 18, 2020 14:37
-
-
Save SimeonGriggs/ef322c4dddb7a8bee12d12fb495cb70b to your computer and use it in GitHub Desktop.
Sanity useCurrentUser() Custom Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import userStore from 'part:@sanity/base/user' | |
import { useEffect, useState } from 'react' | |
// Retrieves the current logged-in user details | |
export function useCurrentUser() { | |
const [user, setUser] = useState() | |
useEffect(() => { | |
userStore.currentUser.subscribe(e => setUser(e.user)) | |
}, []) | |
if (!user) { | |
return {} | |
} | |
return user | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment