react-query-firebase 2.0.0-rc5 → 2.0.0-rc7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/package.json +16 -13
  2. package/{dist/src → react-native}/firestore/useCollectionReference.d.ts +1 -1
  3. package/{src → react-native}/firestore/useCollectionReference.ts +1 -1
  4. package/{dist/src → react-native}/firestore/useDocReference.d.ts +1 -1
  5. package/{dist/src → react-native}/firestore/useDocReference.js +4 -9
  6. package/{src → react-native}/firestore/useDocReference.ts +5 -14
  7. package/web/analytics/index.d.ts +3 -0
  8. package/web/analytics/index.js +3 -0
  9. package/web/analytics/index.ts +3 -0
  10. package/web/analytics/useAnalytics.d.ts +5 -0
  11. package/web/analytics/useAnalytics.js +10 -0
  12. package/web/analytics/useAnalytics.ts +12 -0
  13. package/web/analytics/useLogEvent.d.ts +17 -0
  14. package/web/analytics/useLogEvent.js +21 -0
  15. package/web/analytics/useLogEvent.ts +34 -0
  16. package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +10 -0
  17. package/web/analytics/useSetAnalyticsCollectionEnabled.js +16 -0
  18. package/web/analytics/useSetAnalyticsCollectionEnabled.ts +22 -0
  19. package/web/auth/index.d.ts +13 -0
  20. package/web/auth/index.js +13 -0
  21. package/web/auth/index.ts +13 -0
  22. package/web/auth/mutation-keys.d.ts +7 -0
  23. package/web/auth/mutation-keys.js +19 -0
  24. package/web/auth/mutation-keys.ts +19 -0
  25. package/web/auth/useAuth.d.ts +5 -0
  26. package/web/auth/useAuth.js +10 -0
  27. package/web/auth/useAuth.ts +12 -0
  28. package/web/auth/useAuthStateReady.d.ts +6 -0
  29. package/web/auth/useAuthStateReady.js +19 -0
  30. package/web/auth/useAuthStateReady.ts +24 -0
  31. package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +15 -0
  32. package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +19 -0
  33. package/web/auth/useCreateUserWitEmailAndPasswordMutation.ts +33 -0
  34. package/web/auth/useCurrentUser.d.ts +6 -0
  35. package/web/auth/useCurrentUser.js +20 -0
  36. package/web/auth/useCurrentUser.ts +24 -0
  37. package/web/auth/useIdToken.d.ts +30 -0
  38. package/web/auth/useIdToken.js +66 -0
  39. package/web/auth/useIdToken.ts +83 -0
  40. package/web/auth/useReauthenticateWitCredentialMutation.d.ts +16 -0
  41. package/web/auth/useReauthenticateWitCredentialMutation.js +18 -0
  42. package/web/auth/useReauthenticateWitCredentialMutation.ts +31 -0
  43. package/web/auth/useReauthenticateWitRedirectMutation.d.ts +17 -0
  44. package/web/auth/useReauthenticateWitRedirectMutation.js +18 -0
  45. package/web/auth/useReauthenticateWitRedirectMutation.ts +37 -0
  46. package/web/auth/useSendEmailVerificationMutation.d.ts +13 -0
  47. package/web/auth/useSendEmailVerificationMutation.js +16 -0
  48. package/web/auth/useSendEmailVerificationMutation.ts +28 -0
  49. package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +15 -0
  50. package/web/auth/useSignInWitEmailAndPasswordMutation.js +19 -0
  51. package/web/auth/useSignInWitEmailAndPasswordMutation.ts +34 -0
  52. package/web/auth/useSignInWitRedirectMutation.d.ts +14 -0
  53. package/web/auth/useSignInWitRedirectMutation.js +18 -0
  54. package/web/auth/useSignInWitRedirectMutation.ts +33 -0
  55. package/web/auth/useSignOutMutation.d.ts +10 -0
  56. package/web/auth/useSignOutMutation.js +19 -0
  57. package/web/auth/useSignOutMutation.ts +25 -0
  58. package/web/auth/useUpdateProfileMutation.d.ts +15 -0
  59. package/web/auth/useUpdateProfileMutation.js +17 -0
  60. package/web/auth/useUpdateProfileMutation.ts +30 -0
  61. package/web/context/FirebaseContext.d.ts +19 -0
  62. package/web/context/FirebaseContext.js +8 -0
  63. package/web/context/FirebaseContext.ts +25 -0
  64. package/web/context/FirebaseContextProvider.d.ts +127 -0
  65. package/web/context/FirebaseContextProvider.js +100 -0
  66. package/web/context/FirebaseContextProvider.tsx +231 -0
  67. package/web/context/index.d.ts +1 -0
  68. package/web/context/index.js +1 -0
  69. package/web/context/index.ts +1 -0
  70. package/web/firestore/index.d.ts +16 -0
  71. package/web/firestore/index.js +16 -0
  72. package/web/firestore/index.ts +16 -0
  73. package/web/firestore/useAddDocMutation.d.ts +23 -0
  74. package/web/firestore/useAddDocMutation.js +26 -0
  75. package/web/firestore/useAddDocMutation.ts +62 -0
  76. package/web/firestore/useBatchWrite.d.ts +15 -0
  77. package/web/firestore/useBatchWrite.js +21 -0
  78. package/web/firestore/useBatchWrite.ts +31 -0
  79. package/web/firestore/useCollectionReference.d.ts +18 -0
  80. package/web/firestore/useCollectionReference.js +24 -0
  81. package/web/firestore/useCollectionReference.ts +37 -0
  82. package/web/firestore/useCompositeFilter.d.ts +30 -0
  83. package/web/firestore/useCompositeFilter.js +43 -0
  84. package/web/firestore/useCompositeFilter.ts +86 -0
  85. package/web/firestore/useCountQuery.d.ts +23 -0
  86. package/web/firestore/useCountQuery.js +30 -0
  87. package/web/firestore/useCountQuery.ts +65 -0
  88. package/web/firestore/useDeleteDocMutation.d.ts +18 -0
  89. package/web/firestore/useDeleteDocMutation.js +23 -0
  90. package/web/firestore/useDeleteDocMutation.ts +47 -0
  91. package/web/firestore/useDocReference.d.ts +19 -0
  92. package/web/firestore/useDocReference.js +45 -0
  93. package/web/firestore/useDocReference.ts +68 -0
  94. package/web/firestore/useDocReferences.d.ts +23 -0
  95. package/web/firestore/useDocReferences.js +31 -0
  96. package/web/firestore/useDocReferences.ts +44 -0
  97. package/web/firestore/useFirestore.d.ts +7 -0
  98. package/web/firestore/useFirestore.js +12 -0
  99. package/web/firestore/useFirestore.ts +13 -0
  100. package/web/firestore/useGetDocData.d.ts +18 -0
  101. package/web/firestore/useGetDocData.js +18 -0
  102. package/web/firestore/useGetDocData.ts +41 -0
  103. package/web/firestore/useGetRealtimeDocData.d.ts +57 -0
  104. package/web/firestore/useGetRealtimeDocData.js +56 -0
  105. package/web/firestore/useGetRealtimeDocData.ts +104 -0
  106. package/web/firestore/useInfiniteQuery.d.ts +18 -0
  107. package/web/firestore/useInfiniteQuery.js +28 -0
  108. package/web/firestore/useInfiniteQuery.ts +91 -0
  109. package/web/firestore/useQuery.d.ts +25 -0
  110. package/web/firestore/useQuery.js +34 -0
  111. package/web/firestore/useQuery.ts +72 -0
  112. package/web/firestore/useRunTransaction.d.ts +15 -0
  113. package/web/firestore/useRunTransaction.js +19 -0
  114. package/web/firestore/useRunTransaction.ts +31 -0
  115. package/web/firestore/useSetDocMutation.d.ts +20 -0
  116. package/web/firestore/useSetDocMutation.js +25 -0
  117. package/web/firestore/useSetDocMutation.ts +52 -0
  118. package/web/firestore/useUpdateDocMutation.d.ts +31 -0
  119. package/web/firestore/useUpdateDocMutation.js +37 -0
  120. package/web/firestore/useUpdateDocMutation.ts +74 -0
  121. package/web/firestore/utils/getDocData.d.ts +18 -0
  122. package/web/firestore/utils/getDocData.js +22 -0
  123. package/web/firestore/utils/getDocData.ts +39 -0
  124. package/web/firestore/utils/getDocRef.d.ts +19 -0
  125. package/web/firestore/utils/getDocRef.js +25 -0
  126. package/web/firestore/utils/getDocRef.ts +46 -0
  127. package/web/firestore/utils/getDocSnap.d.ts +20 -0
  128. package/web/firestore/utils/getDocSnap.js +25 -0
  129. package/web/firestore/utils/getDocSnap.ts +41 -0
  130. package/web/index.d.ts +5 -0
  131. package/web/index.js +5 -0
  132. package/web/index.ts +5 -0
  133. package/web/remoteConfig/index.d.ts +3 -0
  134. package/web/remoteConfig/index.js +3 -0
  135. package/web/remoteConfig/index.ts +3 -0
  136. package/web/remoteConfig/useFetchAndActivate.d.ts +11 -0
  137. package/web/remoteConfig/useFetchAndActivate.js +31 -0
  138. package/web/remoteConfig/useFetchAndActivate.ts +36 -0
  139. package/web/remoteConfig/useGetValue.d.ts +7 -0
  140. package/web/remoteConfig/useGetValue.js +15 -0
  141. package/web/remoteConfig/useGetValue.ts +16 -0
  142. package/web/remoteConfig/useRemoteConfig.d.ts +5 -0
  143. package/web/remoteConfig/useRemoteConfig.js +10 -0
  144. package/web/remoteConfig/useRemoteConfig.ts +11 -0
  145. /package/{dist/src → react-native}/analytics/index.d.ts +0 -0
  146. /package/{dist/src → react-native}/analytics/index.js +0 -0
  147. /package/{src → react-native}/analytics/index.ts +0 -0
  148. /package/{dist/src → react-native}/analytics/useAnalytics.d.ts +0 -0
  149. /package/{dist/src → react-native}/analytics/useAnalytics.js +0 -0
  150. /package/{src → react-native}/analytics/useAnalytics.ts +0 -0
  151. /package/{dist/src → react-native}/analytics/useLogEvent.d.ts +0 -0
  152. /package/{dist/src → react-native}/analytics/useLogEvent.js +0 -0
  153. /package/{src → react-native}/analytics/useLogEvent.ts +0 -0
  154. /package/{dist/src → react-native}/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -0
  155. /package/{dist/src → react-native}/analytics/useSetAnalyticsCollectionEnabled.js +0 -0
  156. /package/{src → react-native}/analytics/useSetAnalyticsCollectionEnabled.ts +0 -0
  157. /package/{dist/src → react-native}/auth/index.d.ts +0 -0
  158. /package/{dist/src → react-native}/auth/index.js +0 -0
  159. /package/{src → react-native}/auth/index.ts +0 -0
  160. /package/{dist/src → react-native}/auth/mutation-keys.d.ts +0 -0
  161. /package/{dist/src → react-native}/auth/mutation-keys.js +0 -0
  162. /package/{src → react-native}/auth/mutation-keys.ts +0 -0
  163. /package/{dist/src → react-native}/auth/useAuth.d.ts +0 -0
  164. /package/{dist/src → react-native}/auth/useAuth.js +0 -0
  165. /package/{src → react-native}/auth/useAuth.ts +0 -0
  166. /package/{dist/src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -0
  167. /package/{dist/src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -0
  168. /package/{src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.ts +0 -0
  169. /package/{dist/src → react-native}/auth/useCurrentUser.d.ts +0 -0
  170. /package/{dist/src → react-native}/auth/useCurrentUser.js +0 -0
  171. /package/{src → react-native}/auth/useCurrentUser.ts +0 -0
  172. /package/{dist/src → react-native}/auth/useIdToken.d.ts +0 -0
  173. /package/{dist/src → react-native}/auth/useIdToken.js +0 -0
  174. /package/{src → react-native}/auth/useIdToken.ts +0 -0
  175. /package/{dist/src → react-native}/auth/useReauthenticateWitCredentialMutation.d.ts +0 -0
  176. /package/{dist/src → react-native}/auth/useReauthenticateWitCredentialMutation.js +0 -0
  177. /package/{src → react-native}/auth/useReauthenticateWitCredentialMutation.ts +0 -0
  178. /package/{dist/src → react-native}/auth/useReauthenticateWitRedirectMutation.d.ts +0 -0
  179. /package/{dist/src → react-native}/auth/useReauthenticateWitRedirectMutation.js +0 -0
  180. /package/{src → react-native}/auth/useReauthenticateWitRedirectMutation.ts +0 -0
  181. /package/{dist/src → react-native}/auth/useSendEmailVerificationMutation.d.ts +0 -0
  182. /package/{dist/src → react-native}/auth/useSendEmailVerificationMutation.js +0 -0
  183. /package/{src → react-native}/auth/useSendEmailVerificationMutation.ts +0 -0
  184. /package/{dist/src → react-native}/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -0
  185. /package/{dist/src → react-native}/auth/useSignInWitEmailAndPasswordMutation.js +0 -0
  186. /package/{src → react-native}/auth/useSignInWitEmailAndPasswordMutation.ts +0 -0
  187. /package/{dist/src → react-native}/auth/useSignInWitRedirectMutation.d.ts +0 -0
  188. /package/{dist/src → react-native}/auth/useSignInWitRedirectMutation.js +0 -0
  189. /package/{src → react-native}/auth/useSignInWitRedirectMutation.ts +0 -0
  190. /package/{dist/src → react-native}/auth/useSignOutMutation.d.ts +0 -0
  191. /package/{dist/src → react-native}/auth/useSignOutMutation.js +0 -0
  192. /package/{src → react-native}/auth/useSignOutMutation.ts +0 -0
  193. /package/{dist/src → react-native}/auth/useUpdateProfileMutation.d.ts +0 -0
  194. /package/{dist/src → react-native}/auth/useUpdateProfileMutation.js +0 -0
  195. /package/{src → react-native}/auth/useUpdateProfileMutation.ts +0 -0
  196. /package/{dist/src → react-native}/context/FirebaseContext.d.ts +0 -0
  197. /package/{dist/src → react-native}/context/FirebaseContext.js +0 -0
  198. /package/{src → react-native}/context/FirebaseContext.ts +0 -0
  199. /package/{dist/src → react-native}/context/FirebaseContextProvider.d.ts +0 -0
  200. /package/{dist/src → react-native}/context/FirebaseContextProvider.js +0 -0
  201. /package/{src → react-native}/context/FirebaseContextProvider.tsx +0 -0
  202. /package/{dist/src → react-native}/context/index.d.ts +0 -0
  203. /package/{dist/src → react-native}/context/index.js +0 -0
  204. /package/{src → react-native}/context/index.ts +0 -0
  205. /package/{dist/src → react-native}/firestore/index.d.ts +0 -0
  206. /package/{dist/src → react-native}/firestore/index.js +0 -0
  207. /package/{src → react-native}/firestore/index.ts +0 -0
  208. /package/{dist/src → react-native}/firestore/useAddDocMutation.d.ts +0 -0
  209. /package/{dist/src → react-native}/firestore/useAddDocMutation.js +0 -0
  210. /package/{src → react-native}/firestore/useAddDocMutation.ts +0 -0
  211. /package/{dist/src → react-native}/firestore/useBatchWrite.d.ts +0 -0
  212. /package/{dist/src → react-native}/firestore/useBatchWrite.js +0 -0
  213. /package/{src → react-native}/firestore/useBatchWrite.ts +0 -0
  214. /package/{dist/src → react-native}/firestore/useCollectionReference.js +0 -0
  215. /package/{dist/src → react-native}/firestore/useCompositeFilter.d.ts +0 -0
  216. /package/{dist/src → react-native}/firestore/useCompositeFilter.js +0 -0
  217. /package/{src → react-native}/firestore/useCompositeFilter.ts +0 -0
  218. /package/{dist/src → react-native}/firestore/useCountQuery.d.ts +0 -0
  219. /package/{dist/src → react-native}/firestore/useCountQuery.js +0 -0
  220. /package/{src → react-native}/firestore/useCountQuery.ts +0 -0
  221. /package/{dist/src → react-native}/firestore/useDeleteDocMutation.d.ts +0 -0
  222. /package/{dist/src → react-native}/firestore/useDeleteDocMutation.js +0 -0
  223. /package/{src → react-native}/firestore/useDeleteDocMutation.ts +0 -0
  224. /package/{dist/src → react-native}/firestore/useDocReferences.d.ts +0 -0
  225. /package/{dist/src → react-native}/firestore/useDocReferences.js +0 -0
  226. /package/{src → react-native}/firestore/useDocReferences.ts +0 -0
  227. /package/{dist/src → react-native}/firestore/useFirestore.d.ts +0 -0
  228. /package/{dist/src → react-native}/firestore/useFirestore.js +0 -0
  229. /package/{src → react-native}/firestore/useFirestore.ts +0 -0
  230. /package/{dist/src → react-native}/firestore/useGetDocData.d.ts +0 -0
  231. /package/{dist/src → react-native}/firestore/useGetDocData.js +0 -0
  232. /package/{src → react-native}/firestore/useGetDocData.ts +0 -0
  233. /package/{dist/src → react-native}/firestore/useGetRealtimeDocData.d.ts +0 -0
  234. /package/{dist/src → react-native}/firestore/useGetRealtimeDocData.js +0 -0
  235. /package/{src → react-native}/firestore/useGetRealtimeDocData.ts +0 -0
  236. /package/{dist/src → react-native}/firestore/useInfiniteQuery.d.ts +0 -0
  237. /package/{dist/src → react-native}/firestore/useInfiniteQuery.js +0 -0
  238. /package/{src → react-native}/firestore/useInfiniteQuery.ts +0 -0
  239. /package/{dist/src → react-native}/firestore/useQuery.d.ts +0 -0
  240. /package/{dist/src → react-native}/firestore/useQuery.js +0 -0
  241. /package/{src → react-native}/firestore/useQuery.ts +0 -0
  242. /package/{dist/src → react-native}/firestore/useRunTransaction.d.ts +0 -0
  243. /package/{dist/src → react-native}/firestore/useRunTransaction.js +0 -0
  244. /package/{src → react-native}/firestore/useRunTransaction.ts +0 -0
  245. /package/{dist/src → react-native}/firestore/useSetDocMutation.d.ts +0 -0
  246. /package/{dist/src → react-native}/firestore/useSetDocMutation.js +0 -0
  247. /package/{src → react-native}/firestore/useSetDocMutation.ts +0 -0
  248. /package/{dist/src → react-native}/firestore/useUpdateDocMutation.d.ts +0 -0
  249. /package/{dist/src → react-native}/firestore/useUpdateDocMutation.js +0 -0
  250. /package/{src → react-native}/firestore/useUpdateDocMutation.ts +0 -0
  251. /package/{dist/src → react-native}/firestore/utils/getDocData.d.ts +0 -0
  252. /package/{dist/src → react-native}/firestore/utils/getDocData.js +0 -0
  253. /package/{src → react-native}/firestore/utils/getDocData.ts +0 -0
  254. /package/{dist/src → react-native}/firestore/utils/getDocRef.d.ts +0 -0
  255. /package/{dist/src → react-native}/firestore/utils/getDocRef.js +0 -0
  256. /package/{src → react-native}/firestore/utils/getDocRef.ts +0 -0
  257. /package/{dist/src → react-native}/firestore/utils/getDocSnap.d.ts +0 -0
  258. /package/{dist/src → react-native}/firestore/utils/getDocSnap.js +0 -0
  259. /package/{src → react-native}/firestore/utils/getDocSnap.ts +0 -0
  260. /package/{dist/src → react-native}/index.d.ts +0 -0
  261. /package/{dist/src → react-native}/index.js +0 -0
  262. /package/{src → react-native}/index.ts +0 -0
  263. /package/{dist/src → react-native}/remoteConfig/index.d.ts +0 -0
  264. /package/{dist/src → react-native}/remoteConfig/index.js +0 -0
  265. /package/{src → react-native}/remoteConfig/index.ts +0 -0
  266. /package/{dist/src → react-native}/remoteConfig/useFetchAndActivate.d.ts +0 -0
  267. /package/{dist/src → react-native}/remoteConfig/useFetchAndActivate.js +0 -0
  268. /package/{src → react-native}/remoteConfig/useFetchAndActivate.ts +0 -0
  269. /package/{dist/src → react-native}/remoteConfig/useGetValue.d.ts +0 -0
  270. /package/{dist/src → react-native}/remoteConfig/useGetValue.js +0 -0
  271. /package/{src → react-native}/remoteConfig/useGetValue.ts +0 -0
  272. /package/{dist/src → react-native}/remoteConfig/useRemoteConfig.d.ts +0 -0
  273. /package/{dist/src → react-native}/remoteConfig/useRemoteConfig.js +0 -0
  274. /package/{src → react-native}/remoteConfig/useRemoteConfig.ts +0 -0
@@ -0,0 +1,45 @@
1
+ import { doc } from "firebase/firestore";
2
+ import { useEffect, useRef } from "react";
3
+ import { useFirestore } from "./useFirestore";
4
+ /**
5
+ * Generates a document reference for a specified path or reference in Firestore.
6
+ * If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
7
+ *
8
+ * @param {Firestore} db - The Firestore database instance used to create the document reference.
9
+ * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - An object containing the path, path segments, and optional reference.
10
+ * @param {string} options.path - The path to the document in the Firestore database.
11
+ * @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
12
+ * @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
13
+ *
14
+ * @returns {DocumentReference<AppModelType, DbModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
15
+ */
16
+ const getDocReference = (db, { path, pathSegments, reference }) => {
17
+ if (!path) {
18
+ return null;
19
+ }
20
+ return (!reference
21
+ ? doc(db, path || "", ...(pathSegments || []))
22
+ : reference.type === "collection"
23
+ ? doc(reference, path, ...(pathSegments || []))
24
+ : doc(reference, path, ...(pathSegments || [])));
25
+ };
26
+ /**
27
+ * Custom hook to generate and manage a Firestore document reference.
28
+ * This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
29
+ * The reference is updated whenever the associated path, reference, or path segments change.
30
+ *
31
+ * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - Configuration options for setting up the document reference.
32
+ * @param {string} options.path - The path to the Firestore document.
33
+ * @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
34
+ * @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
35
+ *
36
+ * @returns {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
37
+ */
38
+ export const useDocReference = ({ path, reference, pathSegments }) => {
39
+ const db = useFirestore();
40
+ const ref = useRef(getDocReference(db, { path, pathSegments, reference }));
41
+ useEffect(() => {
42
+ ref.current = getDocReference(db, { path, pathSegments, reference });
43
+ }, [path, reference, pathSegments]);
44
+ return ref.current;
45
+ };
@@ -0,0 +1,68 @@
1
+ import { doc, CollectionReference, DocumentData, DocumentReference, Firestore } from "firebase/firestore";
2
+
3
+ import { useEffect, useRef } from "react";
4
+ import { useFirestore } from "./useFirestore";
5
+
6
+ export type UseDocReferenceOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
7
+ reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
8
+ path?: string;
9
+ pathSegments?: string[];
10
+ };
11
+
12
+ /**
13
+ * Generates a document reference for a specified path or reference in Firestore.
14
+ * If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
15
+ *
16
+ * @param {Firestore} db - The Firestore database instance used to create the document reference.
17
+ * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - An object containing the path, path segments, and optional reference.
18
+ * @param {string} options.path - The path to the document in the Firestore database.
19
+ * @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
20
+ * @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
21
+ *
22
+ * @returns {DocumentReference<AppModelType, DbModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
23
+ */
24
+ const getDocReference = <AppModelType, DbModelType extends DocumentData = DocumentData>(
25
+ db: Firestore,
26
+ { path, pathSegments, reference }: UseDocReferenceOptions<AppModelType, DbModelType>
27
+ ) => {
28
+ if (!path) {
29
+ return null;
30
+ }
31
+
32
+ return (
33
+ !reference
34
+ ? doc(db, path || "", ...(pathSegments || []))
35
+ : reference.type === "collection"
36
+ ? doc(reference, path, ...(pathSegments || []))
37
+ : doc(reference, path, ...(pathSegments || []))
38
+ ) as DocumentReference<AppModelType, DbModelType>;
39
+ };
40
+
41
+ /**
42
+ * Custom hook to generate and manage a Firestore document reference.
43
+ * This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
44
+ * The reference is updated whenever the associated path, reference, or path segments change.
45
+ *
46
+ * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - Configuration options for setting up the document reference.
47
+ * @param {string} options.path - The path to the Firestore document.
48
+ * @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
49
+ * @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
50
+ *
51
+ * @returns {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
52
+ */
53
+ export const useDocReference = <AppModelType, DbModelType extends DocumentData = DocumentData>({
54
+ path,
55
+ reference,
56
+ pathSegments
57
+ }: UseDocReferenceOptions<AppModelType, DbModelType>) => {
58
+ const db = useFirestore();
59
+ const ref = useRef<DocumentReference<AppModelType, DbModelType> | null>(
60
+ getDocReference(db, { path, pathSegments, reference })
61
+ );
62
+
63
+ useEffect(() => {
64
+ ref.current = getDocReference(db, { path, pathSegments, reference });
65
+ }, [path, reference, pathSegments]);
66
+
67
+ return ref.current;
68
+ };
@@ -0,0 +1,23 @@
1
+ import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
+ export type UseDocReferencesOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
3
+ reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
4
+ path: string;
5
+ pathSegments?: string[];
6
+ };
7
+ /**
8
+ * A custom hook to generate document references for Firebase Firestore documents using given
9
+ * reference options.
10
+ *
11
+ * The hook accepts an array of options, where each option may contain a path,
12
+ * an existing reference, or path segments, and returns an array of generated
13
+ * Firestore document references based on those options. The references can be used
14
+ * to interact with the Firestore database documents. It uses memoization to optimize
15
+ * reference generation.
16
+ *
17
+ * @param {UseDocReferencesOptions<AppModelType, DbModelType>[]} references - An array of options
18
+ * specifying how to generate document references. Each option may include a `path`
19
+ * as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
20
+ * @returns {DocumentReference<AppModelType, DbModelType>[]} An array of Firestore document references
21
+ * generated from the options provided.
22
+ */
23
+ export declare const useDocReferences: <AppModelType, DbModelType extends DocumentData = DocumentData>(references: UseDocReferencesOptions<AppModelType, DbModelType>[]) => DocumentReference<AppModelType, DbModelType>[];
@@ -0,0 +1,31 @@
1
+ import { doc } from "firebase/firestore";
2
+ import { useMemo } from "react";
3
+ import { useFirestore } from "./useFirestore";
4
+ /**
5
+ * A custom hook to generate document references for Firebase Firestore documents using given
6
+ * reference options.
7
+ *
8
+ * The hook accepts an array of options, where each option may contain a path,
9
+ * an existing reference, or path segments, and returns an array of generated
10
+ * Firestore document references based on those options. The references can be used
11
+ * to interact with the Firestore database documents. It uses memoization to optimize
12
+ * reference generation.
13
+ *
14
+ * @param {UseDocReferencesOptions<AppModelType, DbModelType>[]} references - An array of options
15
+ * specifying how to generate document references. Each option may include a `path`
16
+ * as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
17
+ * @returns {DocumentReference<AppModelType, DbModelType>[]} An array of Firestore document references
18
+ * generated from the options provided.
19
+ */
20
+ export const useDocReferences = (references) => {
21
+ const db = useFirestore();
22
+ return useMemo(() => {
23
+ return references.map(({ path, reference, pathSegments }) => {
24
+ return (!reference
25
+ ? doc(db, path || "", ...(pathSegments || []))
26
+ : reference.type === "collection"
27
+ ? doc(reference, path, ...(pathSegments || []))
28
+ : doc(reference, path, ...(pathSegments || [])));
29
+ });
30
+ }, [references]);
31
+ };
@@ -0,0 +1,44 @@
1
+ import { CollectionReference, doc, DocumentData, DocumentReference } from "firebase/firestore";
2
+
3
+ import { useMemo } from "react";
4
+ import { useFirestore } from "./useFirestore";
5
+
6
+ export type UseDocReferencesOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
7
+ reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
8
+ path: string;
9
+ pathSegments?: string[];
10
+ };
11
+
12
+ /**
13
+ * A custom hook to generate document references for Firebase Firestore documents using given
14
+ * reference options.
15
+ *
16
+ * The hook accepts an array of options, where each option may contain a path,
17
+ * an existing reference, or path segments, and returns an array of generated
18
+ * Firestore document references based on those options. The references can be used
19
+ * to interact with the Firestore database documents. It uses memoization to optimize
20
+ * reference generation.
21
+ *
22
+ * @param {UseDocReferencesOptions<AppModelType, DbModelType>[]} references - An array of options
23
+ * specifying how to generate document references. Each option may include a `path`
24
+ * as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
25
+ * @returns {DocumentReference<AppModelType, DbModelType>[]} An array of Firestore document references
26
+ * generated from the options provided.
27
+ */
28
+ export const useDocReferences = <AppModelType, DbModelType extends DocumentData = DocumentData>(
29
+ references: UseDocReferencesOptions<AppModelType, DbModelType>[]
30
+ ) => {
31
+ const db = useFirestore();
32
+
33
+ return useMemo(() => {
34
+ return references.map(({ path, reference, pathSegments }) => {
35
+ return (
36
+ !reference
37
+ ? doc(db, path || "", ...(pathSegments || []))
38
+ : reference.type === "collection"
39
+ ? doc(reference, path, ...(pathSegments || []))
40
+ : doc(reference, path, ...(pathSegments || []))
41
+ ) as DocumentReference<AppModelType, DbModelType>;
42
+ });
43
+ }, [references]);
44
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Provides a hook to access the Firestore instance from the Firebase context.
3
+ * It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
4
+ *
5
+ * @returns {firestore.Firestore} The Firestore instance from the Firebase context.
6
+ */
7
+ export declare const useFirestore: () => import("@firebase/firestore").Firestore;
@@ -0,0 +1,12 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+ /**
4
+ * Provides a hook to access the Firestore instance from the Firebase context.
5
+ * It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
6
+ *
7
+ * @returns {firestore.Firestore} The Firestore instance from the Firebase context.
8
+ */
9
+ export const useFirestore = () => {
10
+ const { firestore } = useContext(FirebaseContext);
11
+ return firestore;
12
+ };
@@ -0,0 +1,13 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+
4
+ /**
5
+ * Provides a hook to access the Firestore instance from the Firebase context.
6
+ * It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
7
+ *
8
+ * @returns {firestore.Firestore} The Firestore instance from the Firebase context.
9
+ */
10
+ export const useFirestore = () => {
11
+ const { firestore } = useContext(FirebaseContext);
12
+ return firestore;
13
+ };
@@ -0,0 +1,18 @@
1
+ import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
+ import { UseQueryOptions } from "@tanstack/react-query";
3
+ type UseGetDocOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = {
4
+ options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> & Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
5
+ path?: string;
6
+ pathSegments?: string[];
7
+ reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
8
+ };
9
+ /**
10
+ * Custom React Hook to retrieve document data from Firestore using specified parameters.
11
+ * @param {Object} options - The options for configuring the Firestore query.
12
+ * @param {string} reference - The reference to the document in Firestore.
13
+ * @param {string} path - The path to the document in Firestore.
14
+ * @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
15
+ * @returns {Object} Result of the query containing document data and query status.
16
+ */
17
+ export declare const useGetDocData: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, reference, path, pathSegments }: UseGetDocOptions<AppModelType, DbModelType>) => import("@tanstack/react-query").UseQueryResult<AppModelType, Error>;
18
+ export {};
@@ -0,0 +1,18 @@
1
+ import { useFirestore } from "./useFirestore";
2
+ import { getDocData } from "./utils/getDocData";
3
+ import { useQuery } from "@tanstack/react-query";
4
+ /**
5
+ * Custom React Hook to retrieve document data from Firestore using specified parameters.
6
+ * @param {Object} options - The options for configuring the Firestore query.
7
+ * @param {string} reference - The reference to the document in Firestore.
8
+ * @param {string} path - The path to the document in Firestore.
9
+ * @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
10
+ * @returns {Object} Result of the query containing document data and query status.
11
+ */
12
+ export const useGetDocData = ({ options, reference, path, pathSegments }) => {
13
+ const db = useFirestore();
14
+ return useQuery({
15
+ ...options,
16
+ queryFn: () => getDocData({ db, reference, path, pathSegments })
17
+ });
18
+ };
@@ -0,0 +1,41 @@
1
+ import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
+
3
+ import { useFirestore } from "./useFirestore";
4
+ import { getDocData } from "./utils/getDocData";
5
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
6
+
7
+ type UseGetDocOptions<
8
+ AppModelType extends DocumentData = DocumentData,
9
+ DbModelType extends DocumentData = DocumentData
10
+ > = {
11
+ options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> &
12
+ Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
13
+ path?: string;
14
+ pathSegments?: string[];
15
+ reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
16
+ };
17
+
18
+ /**
19
+ * Custom React Hook to retrieve document data from Firestore using specified parameters.
20
+ * @param {Object} options - The options for configuring the Firestore query.
21
+ * @param {string} reference - The reference to the document in Firestore.
22
+ * @param {string} path - The path to the document in Firestore.
23
+ * @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
24
+ * @returns {Object} Result of the query containing document data and query status.
25
+ */
26
+ export const useGetDocData = <
27
+ AppModelType extends DocumentData = DocumentData,
28
+ DbModelType extends DocumentData = DocumentData
29
+ >({
30
+ options,
31
+ reference,
32
+ path,
33
+ pathSegments
34
+ }: UseGetDocOptions<AppModelType, DbModelType>) => {
35
+ const db = useFirestore();
36
+
37
+ return useQuery({
38
+ ...options,
39
+ queryFn: () => getDocData<AppModelType, DbModelType>({ db, reference, path, pathSegments })
40
+ });
41
+ };
@@ -0,0 +1,57 @@
1
+ import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
+ import { FirebaseError } from "firebase/app";
3
+ /**
4
+ * @inline
5
+ */
6
+ export type UseGetRealtimeDocDataOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
7
+ /**
8
+ * A slash-separated path to a document. Has to be omitted to use
9
+ */
10
+ path?: string;
11
+ /**
12
+ * A reference to a collection.
13
+ */
14
+ reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
15
+ /**
16
+ * Additional path segments that will be applied relative
17
+ * to the first argument.
18
+ */
19
+ pathSegments?: string[];
20
+ /**
21
+ * A callback to be called if the listen fails or is
22
+ * cancelled. No further callbacks will occur.
23
+ */
24
+ onError?: (error: FirebaseError) => unknown;
25
+ };
26
+ /**
27
+ * @inline
28
+ */
29
+ export type UseGetRealtimeDocDataResult<AppModelType> = {
30
+ data: AppModelType | null;
31
+ isError: boolean;
32
+ error: FirebaseError | null;
33
+ isFetching: boolean;
34
+ };
35
+ /**
36
+ * A hook to get realtime updates to a firestore document.
37
+ *
38
+ * @group Hook
39
+ *
40
+ * @param {UseGetRealtimeDocDataOptions<AppModelType, DbModelType>} options
41
+ *
42
+ * @returns {UseGetRealtimeDocDataResult<AppModelType>}
43
+ *
44
+ * @example
45
+ * ```jsx
46
+ * const firebaseConfig = {};
47
+ * export const MyComponent = () => {
48
+ * const result = useGetRealtimeDocData('collection/documentId');
49
+ * return (
50
+ * <div>
51
+ * {JSON.stringify(result)}
52
+ * </div>
53
+ * );
54
+ * };
55
+ * ```
56
+ */
57
+ export declare const useGetRealtimeDocData: <AppModelType, DbModelType extends DocumentData = DocumentData>({ path, pathSegments, reference, onError }: UseGetRealtimeDocDataOptions<AppModelType, DbModelType>) => UseGetRealtimeDocDataResult<AppModelType>;
@@ -0,0 +1,56 @@
1
+ import { onSnapshot } from "firebase/firestore";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { useDocReference } from "./useDocReference";
4
+ /**
5
+ * A hook to get realtime updates to a firestore document.
6
+ *
7
+ * @group Hook
8
+ *
9
+ * @param {UseGetRealtimeDocDataOptions<AppModelType, DbModelType>} options
10
+ *
11
+ * @returns {UseGetRealtimeDocDataResult<AppModelType>}
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * const firebaseConfig = {};
16
+ * export const MyComponent = () => {
17
+ * const result = useGetRealtimeDocData('collection/documentId');
18
+ * return (
19
+ * <div>
20
+ * {JSON.stringify(result)}
21
+ * </div>
22
+ * );
23
+ * };
24
+ * ```
25
+ */
26
+ export const useGetRealtimeDocData = ({ path, pathSegments, reference, onError }) => {
27
+ const ref = useDocReference({ path, reference, pathSegments });
28
+ const [doc, setDoc] = useState(null);
29
+ const [isError, setIsError] = useState(false);
30
+ const [isFetching, setIsFetching] = useState(true);
31
+ const [error, setError] = useState(null);
32
+ useEffect(() => {
33
+ const unsubscribe = ref
34
+ ? onSnapshot(ref, {
35
+ next: async (snapshot) => {
36
+ setIsFetching(false);
37
+ setDoc(snapshot.data() || null);
38
+ setError(null);
39
+ setIsError(false);
40
+ },
41
+ error: (e) => {
42
+ setIsError(true);
43
+ setError(e);
44
+ onError?.(e);
45
+ }
46
+ })
47
+ : () => { };
48
+ return () => unsubscribe();
49
+ }, [ref, doc, isError, onError, isFetching, error]);
50
+ return useMemo(() => ({
51
+ data: doc,
52
+ isError,
53
+ isFetching,
54
+ error
55
+ }), [doc, isError, error]);
56
+ };
@@ -0,0 +1,104 @@
1
+ import { CollectionReference, DocumentData, DocumentReference, onSnapshot } from "firebase/firestore";
2
+
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { FirebaseError } from "firebase/app";
5
+ import { useDocReference } from "./useDocReference";
6
+
7
+ /**
8
+ * @inline
9
+ */
10
+ export type UseGetRealtimeDocDataOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
11
+ /**
12
+ * A slash-separated path to a document. Has to be omitted to use
13
+ */
14
+ path?: string;
15
+ /**
16
+ * A reference to a collection.
17
+ */
18
+ reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
19
+ /**
20
+ * Additional path segments that will be applied relative
21
+ * to the first argument.
22
+ */
23
+ pathSegments?: string[];
24
+ /**
25
+ * A callback to be called if the listen fails or is
26
+ * cancelled. No further callbacks will occur.
27
+ */
28
+ onError?: (error: FirebaseError) => unknown;
29
+ };
30
+
31
+ /**
32
+ * @inline
33
+ */
34
+ export type UseGetRealtimeDocDataResult<AppModelType> = {
35
+ data: AppModelType | null;
36
+ isError: boolean;
37
+ error: FirebaseError | null;
38
+ isFetching: boolean;
39
+ };
40
+
41
+ /**
42
+ * A hook to get realtime updates to a firestore document.
43
+ *
44
+ * @group Hook
45
+ *
46
+ * @param {UseGetRealtimeDocDataOptions<AppModelType, DbModelType>} options
47
+ *
48
+ * @returns {UseGetRealtimeDocDataResult<AppModelType>}
49
+ *
50
+ * @example
51
+ * ```jsx
52
+ * const firebaseConfig = {};
53
+ * export const MyComponent = () => {
54
+ * const result = useGetRealtimeDocData('collection/documentId');
55
+ * return (
56
+ * <div>
57
+ * {JSON.stringify(result)}
58
+ * </div>
59
+ * );
60
+ * };
61
+ * ```
62
+ */
63
+ export const useGetRealtimeDocData = <AppModelType, DbModelType extends DocumentData = DocumentData>({
64
+ path,
65
+ pathSegments,
66
+ reference,
67
+ onError
68
+ }: UseGetRealtimeDocDataOptions<AppModelType, DbModelType>): UseGetRealtimeDocDataResult<AppModelType> => {
69
+ const ref = useDocReference({ path, reference, pathSegments });
70
+ const [doc, setDoc] = useState<AppModelType | null>(null);
71
+ const [isError, setIsError] = useState(false);
72
+ const [isFetching, setIsFetching] = useState(true);
73
+ const [error, setError] = useState<FirebaseError | null>(null);
74
+
75
+ useEffect(() => {
76
+ const unsubscribe = ref
77
+ ? onSnapshot(ref, {
78
+ next: async (snapshot) => {
79
+ setIsFetching(false);
80
+ setDoc(snapshot.data() || null);
81
+ setError(null);
82
+ setIsError(false);
83
+ },
84
+ error: (e) => {
85
+ setIsError(true);
86
+ setError(e);
87
+ onError?.(e);
88
+ }
89
+ })
90
+ : () => {};
91
+
92
+ return () => unsubscribe();
93
+ }, [ref, doc, isError, onError, isFetching, error]);
94
+
95
+ return useMemo(
96
+ () => ({
97
+ data: doc,
98
+ isError,
99
+ isFetching,
100
+ error
101
+ }),
102
+ [doc, isError, error]
103
+ );
104
+ };
@@ -0,0 +1,18 @@
1
+ import { DocumentData, FirestoreDataConverter, Query, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
2
+ import { UseInfiniteQueryOptions as UseReactInfiniteQueryOptions, QueryKey, UseInfiniteQueryResult, InfiniteData } from "@tanstack/react-query";
3
+ type UseInfiniteQueryOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TQueryKey extends QueryKey = QueryKey> = {
4
+ options: Omit<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, QueryConstraint>, "queryFn"> & Required<Pick<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, QueryConstraint>, "queryKey">>;
5
+ query: Query<AppModelType, DbModelType>;
6
+ queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
7
+ compositeFilter?: QueryCompositeFilterConstraint;
8
+ converter?: FirestoreDataConverter<AppModelType, DbModelType>;
9
+ };
10
+ /**
11
+ * Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
12
+ * It fetches data in pages and can load more as required.
13
+ *
14
+ * @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
15
+ * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
16
+ */
17
+ export declare const useInfiniteQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, query: queryReference, queryConstraints, compositeFilter, converter }: UseInfiniteQueryOptions<AppModelType, DbModelType>) => UseInfiniteQueryResult<InfiniteData<AppModelType[]>>;
18
+ export {};
@@ -0,0 +1,28 @@
1
+ import { getDocs, query } from "firebase/firestore";
2
+ import { useInfiniteQuery as useInfiniteReactQuery } from "@tanstack/react-query";
3
+ /**
4
+ * Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
5
+ * It fetches data in pages and can load more as required.
6
+ *
7
+ * @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
8
+ * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
9
+ */
10
+ export const useInfiniteQuery = ({ options, query: queryReference, queryConstraints = [], compositeFilter, converter }) => {
11
+ return useInfiniteReactQuery({
12
+ ...options,
13
+ queryFn: async ({ pageParam }) => {
14
+ const allQueryConstraints = [...queryConstraints, ...(pageParam ? [pageParam] : [])];
15
+ const queryToExecute = compositeFilter
16
+ ? query(queryReference, compositeFilter, ...allQueryConstraints)
17
+ : query(queryReference, ...allQueryConstraints);
18
+ const querySnapshot = await getDocs(converter ? queryToExecute.withConverter(converter) : queryToExecute);
19
+ const docs = [];
20
+ if (querySnapshot) {
21
+ querySnapshot.forEach((doc) => {
22
+ docs.push(doc.data());
23
+ });
24
+ }
25
+ return docs;
26
+ }
27
+ });
28
+ };