react-firehooks
Version:
Lightweight dependency-free collection of React hooks for Firebase
25 lines (24 loc) • 1.53 kB
TypeScript
import { DocumentData, FirestoreError, Query, SnapshotListenOptions, SnapshotOptions } from "firebase/firestore";
import { ValueHookResult } from "../common/types.js";
export type UseQueryDataResult<AppModelType = DocumentData> = ValueHookResult<AppModelType[], FirestoreError>;
/**
* Options to configure the subscription
*/
export interface UseQueryDataOptions<AppModelType = DocumentData> {
snapshotListenOptions?: SnapshotListenOptions | undefined;
snapshotOptions?: SnapshotOptions | undefined;
initialValue?: AppModelType[] | undefined;
}
/**
* Returns and updates a the document data of a Firestore Query
* @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 subscribed to
* @param options Options to configure the subscription
* `initialValue`: Value that is returned while the query is being fetched.
* @returns Query data, loading state, and error
* - value: Query data; `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 useQueryData<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(query: Query<AppModelType, DbModelType> | undefined | null, options?: UseQueryDataOptions<AppModelType> | undefined): UseQueryDataResult<AppModelType>;