Skip to content

Commit

Permalink
[react-hooks] Provide proof-of-concept useUser hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent dae4ec0 commit b8b3246
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/react-hooks/src/@types/parts.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
declare module 'part:@sanity/base/datastore/document'
declare module 'part:@sanity/base/schema'
declare module 'part:@sanity/base/user'
1 change: 1 addition & 0 deletions packages/@sanity/react-hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {useValidationStatus} from './useValidationStatus'
export {useSyncState} from './useSyncState'
export {useConnectionState} from './useConnectionState'
export {useDocumentOperationEvent} from './useDocumentOperationEvent'
export {useUser, LOADING_USER} from './useUser'
14 changes: 14 additions & 0 deletions packages/@sanity/react-hooks/src/useUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import userStore from 'part:@sanity/base/user'
import {useObservable} from './utils/use-observable'

export interface User {
id: string
displayName?: string
imageUrl?: string
}

export const LOADING_USER = Symbol.for('LOADING_USER')

export function useUser(userId): User | null | typeof LOADING_USER {
return useObservable(userStore.observable.getUser(userId))
}

0 comments on commit b8b3246

Please sign in to comment.