react-firehooks
Version:
Lightweight dependency-free collection of React hooks for Firebase
22 lines (21 loc) • 1.42 kB
TypeScript
import { DocumentData, DocumentReference, DocumentSnapshot, FirestoreError, SnapshotListenOptions } from "firebase/firestore";
import type { ValueHookResult } from "../common/types.js";
export type UseDocumentResult<AppModelType = DocumentData> = ValueHookResult<DocumentSnapshot<AppModelType>, FirestoreError>;
/**
* Options to configure the subscription
*/
export interface UseDocumentOptions {
snapshotListenOptions?: SnapshotListenOptions | undefined;
}
/**
* Returns and updates a DocumentSnapshot 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
* @returns Document snapshot, 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 useDocument<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(reference: DocumentReference<AppModelType, DbModelType> | undefined | null, options?: UseDocumentOptions | undefined): UseDocumentResult<AppModelType>;