UNPKG

react-firehooks

Version:

Lightweight dependency-free collection of React hooks for Firebase

30 lines (29 loc) 1.71 kB
import { DocumentData, FirestoreError, Query, SnapshotOptions } from "firebase/firestore"; import type { ValueHookResult } from "../common/types.js"; import type { Source } from "./types.js"; export type UseQueriesDataOnceResult<AppModelTypes extends ReadonlyArray<unknown> = ReadonlyArray<DocumentData>> = { [Index in keyof AppModelTypes]: ValueHookResult<AppModelTypes[Index], FirestoreError>; } & { length: AppModelTypes["length"]; }; /** * Options to configure the subscription */ export interface UseQueriesDataOnceOptions { source?: Source | undefined; snapshotOptions?: SnapshotOptions | undefined; } /** * Returns the data of multiple Firestore queries. Does not update the data once initially fetched * @template AppModelTypes Tuple of shapes of the data after it was converted from firestore * @template DbModelTypes Tuple of shapes of the data in firestore * @param queries Firestore queries that will be fetched * @param options Options to configure how the queries are fetched * @returns Array with tuple for each query: * - 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 useQueriesDataOnce<AppModelTypes extends ReadonlyArray<unknown> = ReadonlyArray<DocumentData>, DbModelTypes extends ReadonlyArray<DocumentData> = ReadonlyArray<DocumentData>>(queries: { [Index in keyof AppModelTypes]: Query<AppModelTypes[Index], DbModelTypes[number]>; }, options?: UseQueriesDataOnceOptions | undefined): UseQueriesDataOnceResult<AppModelTypes>;