UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

26 lines (19 loc) 807 B
import {useContext} from 'react' import {useMemoObservable} from 'react-rx' import {empty} from 'rxjs' import {UserColorManagerContext} from './context' import {type UserColor, type UserColorManager} from './types' /** @internal */ export function useUserColorManager(): UserColorManager { const userColorManager = useContext(UserColorManagerContext) if (!userColorManager) { throw new Error('UserColorManager: missing context value') } return userColorManager } /** @internal */ export function useUserColor(userId: string | null): UserColor { const manager = useUserColorManager() // eslint-disable-next-line react-hooks/exhaustive-deps -- no need to refactor to an inline function return useMemoObservable(userId ? manager.listen(userId) : empty(), [userId], manager.get(null)) }