react-firehooks
Version:
Lightweight dependency-free collection of React hooks for Firebase
23 lines (22 loc) • 1.38 kB
TypeScript
import { DocumentData, FirestoreError, Query, QuerySnapshot } from "firebase/firestore";
import type { ValueHookResult } from "../common/types.js";
import type { Source } from "./types.js";
export type UseQueryOnceResult<AppModelType = DocumentData> = ValueHookResult<QuerySnapshot<AppModelType>, FirestoreError>;
/**
* Options to configure how the query is fetched
*/
export interface UseQueryOnceOptions {
source?: Source | undefined;
}
/**
* Returns the QuerySnapshot of a Firestore query. Does not update the QuerySnapshot once initially fetched
* @template AppModelType Shape of the data after it was converted from firestore
* @template DbModelType Shape of the data in firestore
* @param query Firestore query that will be fetched
* @param options Options to configure how the query is fetched
* @returns QuerySnapshot, loading state, and error
* - value: QuerySnapshot; `undefined` if query is currently being fetched, or an error occurred
* - loading: `true` while fetching the query; `false` if the query was fetched successfully or an error occurred
* - error: `undefined` if no error occurred
*/
export declare function useQueryOnce<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(query: Query<AppModelType, DbModelType> | undefined | null, options?: UseQueryOnceOptions | undefined): UseQueryOnceResult<AppModelType>;