UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

25 lines (24 loc) 1.62 kB
import { DocumentData, DocumentReference, FirestoreError, SnapshotListenOptions, SnapshotOptions } from "firebase/firestore"; import type { ValueHookResult } from "../common/types.js"; export type UseDocumentDataResult<AppModelType = DocumentData> = ValueHookResult<AppModelType, FirestoreError>; /** * Options to configure the subscription */ export interface UseDocumentDataOptions<AppModelType = DocumentData> { snapshotListenOptions?: SnapshotListenOptions | undefined; snapshotOptions?: SnapshotOptions | undefined; initialValue?: AppModelType | undefined; } /** * Returns and updates the data of a Firestore DocumentReference * @template AppModelType Shape of the data after it was converted from firestore * @template DbModelType Shape of the data in firestore * @param reference Firestore DocumentReference that will be subscribed to * @param options Options to configure the subscription * `initialValue`: Value that is returned while the document is being fetched. * @returns Document data, loading state, and error * - value: Document data; `undefined` if document does not exist, is currently being fetched, or an error occurred * - loading: `true` while fetching the document; `false` if the document was fetched successfully or an error occurred * - error: `undefined` if no error occurred */ export declare function useDocumentData<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: DocumentReference<AppModelType, DbModelType> | undefined | null, options?: UseDocumentDataOptions<AppModelType> | undefined): UseDocumentDataResult<AppModelType>;