UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

22 lines (21 loc) 1.3 kB
import { DocumentData, FirestoreError, Query, QuerySnapshot, SnapshotListenOptions } from "firebase/firestore"; import { ValueHookResult } from "../common/types.js"; export type UseQueryResult<AppModelType = DocumentData> = ValueHookResult<QuerySnapshot<AppModelType>, FirestoreError>; /** * Options to configure the subscription */ export interface UseQueryOptions { snapshotListenOptions?: SnapshotListenOptions | undefined; } /** * Returns and updates a QuerySnapshot 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 * @returns QuerySnapshot, loading, 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 useQuery<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(query: Query<AppModelType, DbModelType> | undefined | null, options?: UseQueryOptions | undefined): UseQueryResult<AppModelType>;