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,17 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { updateProfile } from "firebase/auth";
3
+ import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * Custom hook to manage the mutation for updating a user's profile.
6
+ * Utilizes Firebase for updating the user's display name.
7
+ *
8
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
9
+ * @returns {UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
10
+ */
11
+ export const useUpdateProfileMutation = (options = {}) => {
12
+ return useMutation({
13
+ ...options,
14
+ mutationFn: async ({ displayName, user }) => await updateProfile(user, { displayName }),
15
+ mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
16
+ });
17
+ };
@@ -0,0 +1,30 @@
1
+ import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
+ import { updateProfile, User } from "firebase/auth";
3
+ import { FirebaseError } from "firebase/app";
4
+ import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
5
+
6
+ export type UseUpdateProfileMutationVariables = {
7
+ displayName?: string;
8
+ user: User;
9
+ };
10
+
11
+ /**
12
+ * Custom hook to manage the mutation for updating a user's profile.
13
+ * Utilizes Firebase for updating the user's display name.
14
+ *
15
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
16
+ * @returns {UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
17
+ */
18
+ export const useUpdateProfileMutation = <TContext = unknown>(
19
+ options: Omit<
20
+ UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>,
21
+ "mutationKey" | "mutationFn"
22
+ > = {}
23
+ ) => {
24
+ return useMutation({
25
+ ...options,
26
+ mutationFn: async ({ displayName, user }: UseUpdateProfileMutationVariables) =>
27
+ await updateProfile(user, { displayName }),
28
+ mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
29
+ });
30
+ };
@@ -0,0 +1,19 @@
1
+ import { Auth } from "firebase/auth";
2
+ import { Analytics } from "firebase/analytics";
3
+ import { Firestore } from "firebase/firestore";
4
+ import { FirebaseApp } from "firebase/app";
5
+ import { RemoteConfig } from "firebase/remote-config";
6
+ type FirebaseContextValue = {
7
+ auth: Auth;
8
+ analytics: Analytics;
9
+ firebase: FirebaseApp;
10
+ remoteConfig: RemoteConfig;
11
+ firestore: Firestore;
12
+ };
13
+ /**
14
+ * FirebaseContext is a shared context across children that provides access to firebase features
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const FirebaseContext: import("react").Context<FirebaseContextValue>;
19
+ export {};
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { createContext } from "react";
3
+ /**
4
+ * FirebaseContext is a shared context across children that provides access to firebase features
5
+ *
6
+ * @internal
7
+ */
8
+ export const FirebaseContext = createContext({});
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ import { createContext } from "react";
4
+
5
+ import { Auth } from "firebase/auth";
6
+ import { Analytics } from "firebase/analytics";
7
+ import { Firestore } from "firebase/firestore";
8
+ import { FirebaseApp } from "firebase/app";
9
+ import { RemoteConfig } from "firebase/remote-config";
10
+
11
+ type FirebaseContextValue = {
12
+ auth: Auth;
13
+ analytics: Analytics;
14
+ firebase: FirebaseApp;
15
+ remoteConfig: RemoteConfig;
16
+ firestore: Firestore;
17
+ };
18
+
19
+ /**
20
+ * FirebaseContext is a shared context across children that provides access to firebase features
21
+ *
22
+ * @internal
23
+ */
24
+
25
+ export const FirebaseContext = createContext<FirebaseContextValue>({} as FirebaseContextValue);
@@ -0,0 +1,127 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { ConsentSettings } from "firebase/analytics";
3
+ import { RemoteConfigSettings } from "firebase/remote-config";
4
+ import { FirestoreSettings } from "firebase/firestore";
5
+ import { FirebaseOptions } from "firebase/app";
6
+ /**
7
+ * @inline
8
+ */
9
+ export type FirebaseContextProviderFirestoreEmulatorConfig = {
10
+ /**
11
+ * Host to connect to Firebase Firestore Emulator
12
+ */
13
+ host: string;
14
+ /**
15
+ * Port to connect to Firebase Firestore Emulator
16
+ */
17
+ port: number;
18
+ };
19
+ /**
20
+ * @inline
21
+ */
22
+ export type FirebaseContextProviderAuthEmulatorConfig = {
23
+ /**
24
+ * Host to connect to Firebase Auth Emulator
25
+ */
26
+ host: string;
27
+ };
28
+ /**
29
+ * @inline
30
+ */
31
+ export type FirebaseContextProviderEmulators = {
32
+ /**
33
+ * Defines configuration for Firebase Firestore emulator. Optional.
34
+ */
35
+ firestore?: FirebaseContextProviderFirestoreEmulatorConfig;
36
+ /**
37
+ * Defines configuration for Firebase Auth emulator. Optional
38
+ */
39
+ auth?: FirebaseContextProviderAuthEmulatorConfig;
40
+ };
41
+ /**
42
+ * @inline
43
+ */
44
+ export type FirebaseContextProviderProps = PropsWithChildren & {
45
+ /**
46
+ * Defines configuration for firebase emulators
47
+ */
48
+ emulators?: FirebaseContextProviderEmulators;
49
+ /**
50
+ * Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
51
+ */
52
+ options: FirebaseOptions;
53
+ /**
54
+ * Flag indicating whether Firebase Auth should be enabled.
55
+ */
56
+ authEnabled?: boolean;
57
+ /**
58
+ * Flag indicating whether Firebase Analytics should be enabled.
59
+ * @defaultValue `true`
60
+ */
61
+ analyticsEnabled?: boolean;
62
+ /**
63
+ * Default user consent settings. Make sure to either use a consent platform or install custom consent form for a certain regions.
64
+ * @defaultValue {
65
+ * ad_personalization: "denied",
66
+ * ad_storage: "denied",
67
+ * ad_user_data: "denied",
68
+ * analytics_storage: "denied",
69
+ * functionality_storage: "denied",
70
+ * personalization_storage: "denied",
71
+ * security_storage: "denied"
72
+ * }
73
+ */
74
+ consentSettings?: ConsentSettings;
75
+ /**
76
+ * Specifies custom configurations for your Cloud Firestore instance.
77
+ * You must set these before invoking any other methods.
78
+ * {@link https://firebase.google.com/docs/reference/js/firestore_.firestoresettings}
79
+ * @defaultValue {}
80
+ */
81
+ firestoreSettings?: FirestoreSettings;
82
+ /**
83
+ * Flag indicating whether Firebase Firestore should be enabled.
84
+ * @defaultValue `true`
85
+ */
86
+ firestoreEnabled?: boolean;
87
+ /**
88
+ * Configuration options for Firebase Remote Config Settings. {@link https://firebase.google.com/docs/reference/js/remote-config.remoteconfigsettings | Learn about the Firebase Remote COnfig Settings object}
89
+ * @defaultValue `true`
90
+ */
91
+ remoteConfigSettings?: RemoteConfigSettings;
92
+ /**
93
+ * Configuration options for Firebase Remote Config Defaults.
94
+ */
95
+ remoteConfigDefaults?: {
96
+ [key: string]: string | number | boolean;
97
+ };
98
+ /**
99
+ * Flag indicating whether Firebase Remote Config should be enabled.
100
+ * @defaultValue `true`
101
+ */
102
+ remoteConfigEnabled?: boolean;
103
+ };
104
+ /**
105
+ * FirebaseContextProvider component configures and provides Firebase services to its children.
106
+ * Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
107
+ * and Remote Config based on the provided configuration and parameters.
108
+ *
109
+ * @group Component
110
+ *
111
+ * @param {FirebaseContextProviderProps} props
112
+ *
113
+ * @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
114
+ *
115
+ * @example
116
+ * ```jsx
117
+ * const firebaseConfig = {};
118
+ * export const App = () => {
119
+ * return (
120
+ * <FirebaseContextProvider options={firebaseConfig}>
121
+ * <ChildComponent />
122
+ * </FirebaseContextProvider>
123
+ * );
124
+ * };
125
+ * ```
126
+ */
127
+ export declare const FirebaseContextProvider: React.FC<FirebaseContextProviderProps>;
@@ -0,0 +1,100 @@
1
+ import React, { useEffect, useMemo } from "react";
2
+ import { FirebaseContext } from "./FirebaseContext";
3
+ import { connectAuthEmulator, getAuth } from "firebase/auth";
4
+ import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
+ import { getRemoteConfig } from "firebase/remote-config";
6
+ import { connectFirestoreEmulator, initializeFirestore } from "firebase/firestore";
7
+ import { initializeApp } from "firebase/app";
8
+ /**
9
+ * FirebaseContextProvider component configures and provides Firebase services to its children.
10
+ * Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
11
+ * and Remote Config based on the provided configuration and parameters.
12
+ *
13
+ * @group Component
14
+ *
15
+ * @param {FirebaseContextProviderProps} props
16
+ *
17
+ * @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
18
+ *
19
+ * @example
20
+ * ```jsx
21
+ * const firebaseConfig = {};
22
+ * export const App = () => {
23
+ * return (
24
+ * <FirebaseContextProvider options={firebaseConfig}>
25
+ * <ChildComponent />
26
+ * </FirebaseContextProvider>
27
+ * );
28
+ * };
29
+ * ```
30
+ */
31
+ export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
32
+ const firebase = useMemo(() => {
33
+ return initializeApp(options);
34
+ }, [options]);
35
+ useEffect(() => {
36
+ setConsent({
37
+ ad_personalization: "denied",
38
+ ad_storage: "denied",
39
+ ad_user_data: "denied",
40
+ analytics_storage: "denied",
41
+ functionality_storage: "denied",
42
+ personalization_storage: "denied",
43
+ security_storage: "denied",
44
+ ...consentSettings
45
+ });
46
+ }, [consentSettings]);
47
+ const firestore = useMemo(() => {
48
+ if (firestoreEnabled) {
49
+ const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
50
+ if (emulators?.firestore?.host && emulators?.firestore?.port) {
51
+ connectFirestoreEmulator(localFirestore, emulators.firestore.host, emulators.firestore.port);
52
+ }
53
+ return localFirestore;
54
+ }
55
+ return null;
56
+ }, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
57
+ const auth = useMemo(() => {
58
+ if (authEnabled) {
59
+ const localAuth = getAuth(firebase);
60
+ if (emulators?.auth?.host) {
61
+ connectAuthEmulator(localAuth, emulators?.auth?.host, {
62
+ disableWarnings: true
63
+ });
64
+ }
65
+ return localAuth;
66
+ }
67
+ return null;
68
+ }, [emulators?.auth, authEnabled]);
69
+ const analytics = useMemo(() => {
70
+ if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
71
+ return getAnalytics(firebase);
72
+ }
73
+ return null;
74
+ }, [analyticsEnabled, options.measurementId]);
75
+ const remoteConfig = useMemo(() => {
76
+ if (remoteConfigEnabled && typeof window !== "undefined") {
77
+ const localRemoteConfig = getRemoteConfig(firebase);
78
+ if (remoteConfigSettings) {
79
+ localRemoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
80
+ localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
81
+ localRemoteConfig.defaultConfig = remoteConfigDefaults;
82
+ }
83
+ return localRemoteConfig;
84
+ }
85
+ return null;
86
+ }, [remoteConfigEnabled]);
87
+ const contextValue = useMemo(() => ({
88
+ firebase,
89
+ auth,
90
+ analytics,
91
+ firestore,
92
+ remoteConfig
93
+ }), [firebase, auth, analytics, firestore, remoteConfig]);
94
+ useEffect(() => {
95
+ if (contextValue.analytics) {
96
+ setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
97
+ }
98
+ }, [consentSettings]);
99
+ return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
100
+ };
@@ -0,0 +1,231 @@
1
+ import React, { PropsWithChildren, useEffect, useMemo } from "react";
2
+ import { FirebaseContext } from "./FirebaseContext";
3
+ import { connectAuthEmulator, getAuth } from "firebase/auth";
4
+ import { ConsentSettings, getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
+ import { getRemoteConfig, RemoteConfigSettings } from "firebase/remote-config";
6
+ import { connectFirestoreEmulator, FirestoreSettings, initializeFirestore } from "firebase/firestore";
7
+ import { FirebaseOptions, initializeApp } from "firebase/app";
8
+
9
+ /**
10
+ * @inline
11
+ */
12
+ export type FirebaseContextProviderFirestoreEmulatorConfig = {
13
+ /**
14
+ * Host to connect to Firebase Firestore Emulator
15
+ */
16
+ host: string;
17
+ /**
18
+ * Port to connect to Firebase Firestore Emulator
19
+ */
20
+ port: number;
21
+ };
22
+
23
+ /**
24
+ * @inline
25
+ */
26
+ export type FirebaseContextProviderAuthEmulatorConfig = {
27
+ /**
28
+ * Host to connect to Firebase Auth Emulator
29
+ */
30
+ host: string;
31
+ };
32
+
33
+ /**
34
+ * @inline
35
+ */
36
+ export type FirebaseContextProviderEmulators = {
37
+ /**
38
+ * Defines configuration for Firebase Firestore emulator. Optional.
39
+ */
40
+ firestore?: FirebaseContextProviderFirestoreEmulatorConfig;
41
+ /**
42
+ * Defines configuration for Firebase Auth emulator. Optional
43
+ */
44
+ auth?: FirebaseContextProviderAuthEmulatorConfig;
45
+ };
46
+
47
+ /**
48
+ * @inline
49
+ */
50
+ export type FirebaseContextProviderProps = PropsWithChildren & {
51
+ /**
52
+ * Defines configuration for firebase emulators
53
+ */
54
+ emulators?: FirebaseContextProviderEmulators;
55
+ /**
56
+ * Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
57
+ */
58
+ options: FirebaseOptions;
59
+ /**
60
+ * Flag indicating whether Firebase Auth should be enabled.
61
+ */
62
+ authEnabled?: boolean;
63
+ /**
64
+ * Flag indicating whether Firebase Analytics should be enabled.
65
+ * @defaultValue `true`
66
+ */
67
+ analyticsEnabled?: boolean;
68
+ /**
69
+ * Default user consent settings. Make sure to either use a consent platform or install custom consent form for a certain regions.
70
+ * @defaultValue {
71
+ * ad_personalization: "denied",
72
+ * ad_storage: "denied",
73
+ * ad_user_data: "denied",
74
+ * analytics_storage: "denied",
75
+ * functionality_storage: "denied",
76
+ * personalization_storage: "denied",
77
+ * security_storage: "denied"
78
+ * }
79
+ */
80
+ consentSettings?: ConsentSettings;
81
+ /**
82
+ * Specifies custom configurations for your Cloud Firestore instance.
83
+ * You must set these before invoking any other methods.
84
+ * {@link https://firebase.google.com/docs/reference/js/firestore_.firestoresettings}
85
+ * @defaultValue {}
86
+ */
87
+ firestoreSettings?: FirestoreSettings;
88
+ /**
89
+ * Flag indicating whether Firebase Firestore should be enabled.
90
+ * @defaultValue `true`
91
+ */
92
+ firestoreEnabled?: boolean;
93
+ /**
94
+ * Configuration options for Firebase Remote Config Settings. {@link https://firebase.google.com/docs/reference/js/remote-config.remoteconfigsettings | Learn about the Firebase Remote COnfig Settings object}
95
+ * @defaultValue `true`
96
+ */
97
+ remoteConfigSettings?: RemoteConfigSettings;
98
+ /**
99
+ * Configuration options for Firebase Remote Config Defaults.
100
+ */
101
+ remoteConfigDefaults?: { [key: string]: string | number | boolean };
102
+ /**
103
+ * Flag indicating whether Firebase Remote Config should be enabled.
104
+ * @defaultValue `true`
105
+ */
106
+ remoteConfigEnabled?: boolean;
107
+ };
108
+
109
+ /**
110
+ * FirebaseContextProvider component configures and provides Firebase services to its children.
111
+ * Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
112
+ * and Remote Config based on the provided configuration and parameters.
113
+ *
114
+ * @group Component
115
+ *
116
+ * @param {FirebaseContextProviderProps} props
117
+ *
118
+ * @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
119
+ *
120
+ * @example
121
+ * ```jsx
122
+ * const firebaseConfig = {};
123
+ * export const App = () => {
124
+ * return (
125
+ * <FirebaseContextProvider options={firebaseConfig}>
126
+ * <ChildComponent />
127
+ * </FirebaseContextProvider>
128
+ * );
129
+ * };
130
+ * ```
131
+ */
132
+ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = ({
133
+ emulators,
134
+ options,
135
+ children,
136
+ authEnabled = true,
137
+ firestoreEnabled = true,
138
+ analyticsEnabled = true,
139
+ consentSettings = {},
140
+ remoteConfigEnabled = true,
141
+ remoteConfigSettings,
142
+ remoteConfigDefaults = {},
143
+ firestoreSettings
144
+ }) => {
145
+ const firebase = useMemo(() => {
146
+ return initializeApp(options);
147
+ }, [options]);
148
+
149
+ useEffect(() => {
150
+ setConsent({
151
+ ad_personalization: "denied",
152
+ ad_storage: "denied",
153
+ ad_user_data: "denied",
154
+ analytics_storage: "denied",
155
+ functionality_storage: "denied",
156
+ personalization_storage: "denied",
157
+ security_storage: "denied",
158
+ ...consentSettings
159
+ });
160
+ }, [consentSettings]);
161
+
162
+ const firestore = useMemo(() => {
163
+ if (firestoreEnabled) {
164
+ const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
165
+
166
+ if (emulators?.firestore?.host && emulators?.firestore?.port) {
167
+ connectFirestoreEmulator(localFirestore, emulators.firestore.host, emulators.firestore.port);
168
+ }
169
+
170
+ return localFirestore;
171
+ }
172
+
173
+ return null;
174
+ }, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
175
+
176
+ const auth = useMemo(() => {
177
+ if (authEnabled) {
178
+ const localAuth = getAuth(firebase);
179
+ if (emulators?.auth?.host) {
180
+ connectAuthEmulator(localAuth, emulators?.auth?.host, {
181
+ disableWarnings: true
182
+ });
183
+ }
184
+ return localAuth;
185
+ }
186
+ return null;
187
+ }, [emulators?.auth, authEnabled]);
188
+
189
+ const analytics = useMemo(() => {
190
+ if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
191
+ return getAnalytics(firebase);
192
+ }
193
+ return null;
194
+ }, [analyticsEnabled, options.measurementId]);
195
+
196
+ const remoteConfig = useMemo(() => {
197
+ if (remoteConfigEnabled && typeof window !== "undefined") {
198
+ const localRemoteConfig = getRemoteConfig(firebase);
199
+ if (remoteConfigSettings) {
200
+ localRemoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
201
+ localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
202
+ localRemoteConfig.defaultConfig = remoteConfigDefaults;
203
+ }
204
+ return localRemoteConfig;
205
+ }
206
+ return null;
207
+ }, [remoteConfigEnabled]);
208
+
209
+ const contextValue = useMemo(
210
+ () => ({
211
+ firebase,
212
+ auth,
213
+ analytics,
214
+ firestore,
215
+ remoteConfig
216
+ }),
217
+ [firebase, auth, analytics, firestore, remoteConfig]
218
+ );
219
+
220
+ useEffect(() => {
221
+ if (contextValue.analytics) {
222
+ setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
223
+ }
224
+ }, [consentSettings]);
225
+
226
+ return (
227
+ <FirebaseContext.Provider value={contextValue as React.ContextType<typeof FirebaseContext>}>
228
+ {children}
229
+ </FirebaseContext.Provider>
230
+ );
231
+ };
@@ -0,0 +1 @@
1
+ export * from "./FirebaseContextProvider";
@@ -0,0 +1 @@
1
+ export * from "./FirebaseContextProvider";
@@ -0,0 +1 @@
1
+ export * from "./FirebaseContextProvider";
@@ -0,0 +1,16 @@
1
+ export * from "./useFirestore";
2
+ export * from "./useAddDocMutation";
3
+ export * from "./useBatchWrite";
4
+ export * from "./useCollectionReference";
5
+ export * from "./useCompositeFilter";
6
+ export * from "./useCountQuery";
7
+ export * from "./useDeleteDocMutation";
8
+ export * from "./useDocReference";
9
+ export * from "./useDocReferences";
10
+ export * from "./useGetDocData";
11
+ export * from "./useInfiniteQuery";
12
+ export * from "./useQuery";
13
+ export * from "./useRunTransaction";
14
+ export * from "./useSetDocMutation";
15
+ export * from "./useUpdateDocMutation";
16
+ export * from "./useGetRealtimeDocData";
@@ -0,0 +1,16 @@
1
+ export * from "./useFirestore";
2
+ export * from "./useAddDocMutation";
3
+ export * from "./useBatchWrite";
4
+ export * from "./useCollectionReference";
5
+ export * from "./useCompositeFilter";
6
+ export * from "./useCountQuery";
7
+ export * from "./useDeleteDocMutation";
8
+ export * from "./useDocReference";
9
+ export * from "./useDocReferences";
10
+ export * from "./useGetDocData";
11
+ export * from "./useInfiniteQuery";
12
+ export * from "./useQuery";
13
+ export * from "./useRunTransaction";
14
+ export * from "./useSetDocMutation";
15
+ export * from "./useUpdateDocMutation";
16
+ export * from "./useGetRealtimeDocData";
@@ -0,0 +1,16 @@
1
+ export * from "./useFirestore";
2
+ export * from "./useAddDocMutation";
3
+ export * from "./useBatchWrite";
4
+ export * from "./useCollectionReference";
5
+ export * from "./useCompositeFilter";
6
+ export * from "./useCountQuery";
7
+ export * from "./useDeleteDocMutation";
8
+ export * from "./useDocReference";
9
+ export * from "./useDocReferences";
10
+ export * from "./useGetDocData";
11
+ export * from "./useInfiniteQuery";
12
+ export * from "./useQuery";
13
+ export * from "./useRunTransaction";
14
+ export * from "./useSetDocMutation";
15
+ export * from "./useUpdateDocMutation";
16
+ export * from "./useGetRealtimeDocData";
@@ -0,0 +1,23 @@
1
+ import { UseMutationOptions } from "@tanstack/react-query";
2
+ import { DocumentData, WithFieldValue, CollectionReference, FirestoreDataConverter } from "firebase/firestore";
3
+ import { FirebaseError } from "firebase/app";
4
+ export type UseAddDocMutationValues<AppModelType> = {
5
+ data: WithFieldValue<AppModelType>;
6
+ };
7
+ export type UseAddDocMutationOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown> = {
8
+ reference: CollectionReference<AppModelType, DbModelType>;
9
+ converter?: FirestoreDataConverter<AppModelType, DbModelType>;
10
+ options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
11
+ };
12
+ /**
13
+ * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
14
+ * It handles addition and optional conversion of the document data in Firestore.
15
+ *
16
+ * @param {Object} options - Options for the mutation hook
17
+ * @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
18
+ * @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
19
+ * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
20
+ *
21
+ * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
22
+ */
23
+ export declare const useAddDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, converter, options }: UseAddDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
@@ -0,0 +1,26 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { addDoc, getDoc } from "firebase/firestore";
3
+ import { useMemo } from "react";
4
+ /**
5
+ * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
6
+ * It handles addition and optional conversion of the document data in Firestore.
7
+ *
8
+ * @param {Object} options - Options for the mutation hook
9
+ * @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
10
+ * @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
11
+ * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
12
+ *
13
+ * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
14
+ */
15
+ export const useAddDocMutation = ({ reference, converter, options = {} }) => {
16
+ const mutationKey = useMemo(() => [reference.path], [reference.path]);
17
+ return useMutation({
18
+ ...options,
19
+ mutationFn: async ({ data }) => {
20
+ const docRef = await addDoc(reference, data);
21
+ const docSnap = await getDoc(converter ? docRef.withConverter(converter) : docRef);
22
+ return docSnap.data();
23
+ },
24
+ mutationKey
25
+ });
26
+ };