UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

23 lines (22 loc) 1.5 kB
import { DocumentData, DocumentReference, DocumentSnapshot, FirestoreError } from "firebase/firestore"; import type { ValueHookResult } from "../common/types.js"; import type { Source } from "./types.js"; export type UseDocumentOnceResult<AppModelType = DocumentData> = ValueHookResult<DocumentSnapshot<AppModelType>, FirestoreError>; /** * Options to configure how the document is fetched */ export interface UseDocumentOnceOptions { source?: Source | undefined; } /** * Returns the DocumentSnapshot of a Firestore DocumentReference. Does not update the DocumentSnapshot once initially fetched * @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 fetched * @param options Options to configure how the document is fetched * @returns DocumentSnapshot, loading state, and error * - value: DocumentSnapshot; `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 useDocumentOnce<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: DocumentReference<AppModelType, DbModelType> | undefined | null, options?: UseDocumentOnceOptions | undefined): UseDocumentOnceResult<AppModelType>;