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

27 lines (22 loc) 735 B
import {useMemo} from 'react' import {type Observable, of} from 'rxjs' import {type LoadableState, useLoadable} from '../../../../util' import {useDocumentPreviewStore} from '../../datastores' /** @internal */ export function useDocumentValues<T = Record<string, unknown>>( documentId: string, paths: string[], ): LoadableState<T | undefined> { const documentPreviewStore = useDocumentPreviewStore() const documentValues$ = useMemo( () => documentId ? (documentPreviewStore.observePaths( {_type: 'reference', _ref: documentId}, paths, ) as Observable<T>) : of(undefined), [documentId, documentPreviewStore, paths], ) return useLoadable(documentValues$) }