Skip to content

Instantly share code, notes, and snippets.

@SimeonGriggs
Created November 18, 2020 14:37
Show Gist options
  • Save SimeonGriggs/ef322c4dddb7a8bee12d12fb495cb70b to your computer and use it in GitHub Desktop.
Save SimeonGriggs/ef322c4dddb7a8bee12d12fb495cb70b to your computer and use it in GitHub Desktop.
Sanity useCurrentUser() Custom Hook
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