react-query-firebase 2.1.3 → 2.2.0

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.
package/package.json CHANGED
@@ -74,5 +74,5 @@
74
74
  "docs:build": "vitepress build docs",
75
75
  "docs:preview": "vitepress preview docs"
76
76
  },
77
- "version": "2.1.3"
77
+ "version": "2.2.0"
78
78
  }
@@ -10,3 +10,4 @@ export * from "./useSignOutMutation";
10
10
  export * from "./useIdToken";
11
11
  export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
+ export * from "./useAuthStateReady";
@@ -10,3 +10,4 @@ export * from "./useSignOutMutation";
10
10
  export * from "./useIdToken";
11
11
  export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
+ export * from "./useAuthStateReady";
@@ -10,3 +10,4 @@ export * from "./useSignOutMutation";
10
10
  export * from "./useIdToken";
11
11
  export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
+ export * from "./useAuthStateReady";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A custom hook that determines if the Firebase authentication state is ready.
3
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
4
+ *
5
+ * @group Hook
6
+ *
7
+ * @returns {boolean}
8
+ *
9
+ * @example
10
+ * ```jsx
11
+ * export const MyComponent = () => {
12
+ * const isAuthStateReady = useAuthStateReady();
13
+ * console.log(isAuthStateReady);
14
+ * };
15
+ * ```
16
+ */
17
+ export declare const useAuthStateReady: () => boolean;
@@ -0,0 +1,33 @@
1
+ import { useAuth } from "./useAuth";
2
+ import { useEffect, useState } from "react";
3
+ /**
4
+ * A custom hook that determines if the Firebase authentication state is ready.
5
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
6
+ *
7
+ * @group Hook
8
+ *
9
+ * @returns {boolean}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const isAuthStateReady = useAuthStateReady();
15
+ * console.log(isAuthStateReady);
16
+ * };
17
+ * ```
18
+ */
19
+ export const useAuthStateReady = () => {
20
+ const firebaseAuth = useAuth();
21
+ const [isAuthStateReady, setIsAuthStateReady] = useState(false);
22
+ useEffect(() => {
23
+ const subscription = firebaseAuth.onAuthStateChanged(() => {
24
+ if (!isAuthStateReady) {
25
+ setIsAuthStateReady(true);
26
+ }
27
+ });
28
+ return () => {
29
+ subscription();
30
+ };
31
+ }, [firebaseAuth, isAuthStateReady]);
32
+ return isAuthStateReady;
33
+ };
@@ -0,0 +1,38 @@
1
+ import { useAuth } from "./useAuth";
2
+ import { useEffect, useState } from "react";
3
+
4
+ /**
5
+ * A custom hook that determines if the Firebase authentication state is ready.
6
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
7
+ *
8
+ * @group Hook
9
+ *
10
+ * @returns {boolean}
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * export const MyComponent = () => {
15
+ * const isAuthStateReady = useAuthStateReady();
16
+ * console.log(isAuthStateReady);
17
+ * };
18
+ * ```
19
+ */
20
+ export const useAuthStateReady = () => {
21
+ const firebaseAuth = useAuth();
22
+
23
+ const [isAuthStateReady, setIsAuthStateReady] = useState(false);
24
+
25
+ useEffect(() => {
26
+ const subscription = firebaseAuth.onAuthStateChanged(() => {
27
+ if (!isAuthStateReady) {
28
+ setIsAuthStateReady(true);
29
+ }
30
+ });
31
+
32
+ return () => {
33
+ subscription();
34
+ };
35
+ }, [firebaseAuth, isAuthStateReady]);
36
+
37
+ return isAuthStateReady;
38
+ };
@@ -1,8 +1,9 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { FirebaseContext } from "./FirebaseContext";
3
- import { connectAuthEmulator } from "@react-native-firebase/auth";
4
- import { setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
5
- import { connectFirestoreEmulator } from "@react-native-firebase/firestore";
3
+ import auth, { connectAuthEmulator } from "@react-native-firebase/auth";
4
+ import analytics, { setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
5
+ import remoteConfig from "@react-native-firebase/remote-config";
6
+ import firestore, { connectFirestoreEmulator } from "@react-native-firebase/firestore";
6
7
  import firebase from "@react-native-firebase/app";
7
8
  /**
8
9
  * FirebaseContextProvider component configures and provides Firebase services to its children.
@@ -30,7 +31,7 @@ import firebase from "@react-native-firebase/app";
30
31
  export const FirebaseContextProvider = ({ emulators, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
31
32
  const internalFirebase = useMemo(() => firebase, []);
32
33
  useEffect(() => {
33
- setConsent(firebase.analytics(), {
34
+ setConsent(analytics(), {
34
35
  ad_personalization: false,
35
36
  ad_storage: false,
36
37
  ad_user_data: false,
@@ -44,19 +45,19 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
44
45
  const internalFirestore = useMemo(() => {
45
46
  if (firestoreEnabled) {
46
47
  if (emulators?.firestore?.host && emulators?.firestore?.port) {
47
- connectFirestoreEmulator(internalFirebase.firestore(), emulators.firestore.host, emulators.firestore.port);
48
+ connectFirestoreEmulator(firestore(), emulators.firestore.host, emulators.firestore.port);
48
49
  }
49
- const localFirestore = internalFirebase.firestore();
50
+ const localFirestore = firestore();
50
51
  if (firestoreSettings) {
51
52
  localFirestore.settings(firestoreSettings);
52
53
  }
53
54
  return localFirestore;
54
55
  }
55
56
  return null;
56
- }, [emulators?.firestore, firestoreEnabled, internalFirebase, firestoreSettings]);
57
+ }, [emulators?.firestore, firestoreEnabled, firestoreSettings]);
57
58
  const internalAuth = useMemo(() => {
58
59
  if (authEnabled) {
59
- const localAuth = internalFirebase.auth();
60
+ const localAuth = auth();
60
61
  if (emulators?.auth?.host) {
61
62
  connectAuthEmulator(localAuth, emulators?.auth?.host, {
62
63
  disableWarnings: true
@@ -65,16 +66,16 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
65
66
  return localAuth;
66
67
  }
67
68
  return null;
68
- }, [emulators?.auth, authEnabled, internalFirebase]);
69
+ }, [emulators?.auth, authEnabled]);
69
70
  const internalAnalytics = useMemo(() => {
70
71
  if (analyticsEnabled) {
71
- return internalFirebase.analytics();
72
+ return analytics();
72
73
  }
73
74
  return null;
74
- }, [analyticsEnabled, internalFirebase]);
75
+ }, [analyticsEnabled]);
75
76
  const internalRemoteConfig = useMemo(() => {
76
77
  if (remoteConfigEnabled) {
77
- const localRemoteConfig = internalFirebase.remoteConfig();
78
+ const localRemoteConfig = remoteConfig();
78
79
  if (remoteConfigSettings) {
79
80
  localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
80
81
  localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
@@ -83,7 +84,7 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
83
84
  return localRemoteConfig;
84
85
  }
85
86
  return null;
86
- }, [remoteConfigEnabled, remoteConfigSettings, internalFirebase, remoteConfigDefaults]);
87
+ }, [remoteConfigEnabled, remoteConfigSettings, remoteConfigDefaults]);
87
88
  const contextValue = useMemo(() => ({
88
89
  firebase: internalFirebase,
89
90
  auth: internalAuth,
@@ -1,9 +1,13 @@
1
1
  import React, { PropsWithChildren, useEffect, useMemo } from "react";
2
2
  import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
3
- import { connectAuthEmulator } from "@react-native-firebase/auth";
4
- import { FirebaseAnalyticsTypes, setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
5
- import { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
6
- import { connectFirestoreEmulator } from "@react-native-firebase/firestore";
3
+ import auth, { connectAuthEmulator } from "@react-native-firebase/auth";
4
+ import analytics, {
5
+ FirebaseAnalyticsTypes,
6
+ setAnalyticsCollectionEnabled,
7
+ setConsent
8
+ } from "@react-native-firebase/analytics";
9
+ import remoteConfig, { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
10
+ import firestore, { connectFirestoreEmulator } from "@react-native-firebase/firestore";
7
11
  import firebase, { ReactNativeFirebase } from "@react-native-firebase/app";
8
12
 
9
13
  /**
@@ -163,7 +167,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
163
167
  const internalFirebase = useMemo(() => firebase, []);
164
168
 
165
169
  useEffect(() => {
166
- setConsent(firebase.analytics(), {
170
+ setConsent(analytics(), {
167
171
  ad_personalization: false,
168
172
  ad_storage: false,
169
173
  ad_user_data: false,
@@ -178,14 +182,10 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
178
182
  const internalFirestore = useMemo(() => {
179
183
  if (firestoreEnabled) {
180
184
  if (emulators?.firestore?.host && emulators?.firestore?.port) {
181
- connectFirestoreEmulator(
182
- internalFirebase.firestore(),
183
- emulators.firestore.host,
184
- emulators.firestore.port
185
- );
185
+ connectFirestoreEmulator(firestore(), emulators.firestore.host, emulators.firestore.port);
186
186
  }
187
187
 
188
- const localFirestore = internalFirebase.firestore();
188
+ const localFirestore = firestore();
189
189
  if (firestoreSettings) {
190
190
  localFirestore.settings(firestoreSettings);
191
191
  }
@@ -193,11 +193,11 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
193
193
  }
194
194
 
195
195
  return null;
196
- }, [emulators?.firestore, firestoreEnabled, internalFirebase, firestoreSettings]);
196
+ }, [emulators?.firestore, firestoreEnabled, firestoreSettings]);
197
197
 
198
198
  const internalAuth = useMemo(() => {
199
199
  if (authEnabled) {
200
- const localAuth = internalFirebase.auth();
200
+ const localAuth = auth();
201
201
  if (emulators?.auth?.host) {
202
202
  connectAuthEmulator(localAuth, emulators?.auth?.host, {
203
203
  disableWarnings: true
@@ -206,18 +206,18 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
206
206
  return localAuth;
207
207
  }
208
208
  return null;
209
- }, [emulators?.auth, authEnabled, internalFirebase]);
209
+ }, [emulators?.auth, authEnabled]);
210
210
 
211
211
  const internalAnalytics = useMemo(() => {
212
212
  if (analyticsEnabled) {
213
- return internalFirebase.analytics();
213
+ return analytics();
214
214
  }
215
215
  return null;
216
- }, [analyticsEnabled, internalFirebase]);
216
+ }, [analyticsEnabled]);
217
217
 
218
218
  const internalRemoteConfig = useMemo(() => {
219
219
  if (remoteConfigEnabled) {
220
- const localRemoteConfig = internalFirebase.remoteConfig();
220
+ const localRemoteConfig = remoteConfig();
221
221
  if (remoteConfigSettings) {
222
222
  localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
223
223
  localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
@@ -226,7 +226,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
226
226
  return localRemoteConfig;
227
227
  }
228
228
  return null;
229
- }, [remoteConfigEnabled, remoteConfigSettings, internalFirebase, remoteConfigDefaults]);
229
+ }, [remoteConfigEnabled, remoteConfigSettings, remoteConfigDefaults]);
230
230
 
231
231
  const contextValue = useMemo(
232
232
  () => ({
@@ -36,5 +36,5 @@ export declare const buildCompositeFilter: <DbModelType extends CompositeFilterD
36
36
  *
37
37
  * @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
38
38
  */
39
- export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.QueryCompositeFilterConstraint | undefined;
39
+ export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.QueryFilterConstraint | undefined;
40
40
  export {};
@@ -13,6 +13,9 @@ export const buildCompositeFilter = (query) => {
13
13
  if (queryConstraints.length <= 0) {
14
14
  return null;
15
15
  }
16
+ if (queryConstraints.length <= 1) {
17
+ return queryConstraints[0];
18
+ }
16
19
  return query.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
17
20
  }
18
21
  if (query.field && query.op) {
@@ -37,6 +40,9 @@ export const useCompositeFilter = ({ query }) => {
37
40
  if (queryConstraints.length <= 0) {
38
41
  return undefined;
39
42
  }
43
+ if (queryConstraints.length <= 1) {
44
+ return queryConstraints[0];
45
+ }
40
46
  return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
41
47
  }, [query]);
42
48
  };
@@ -38,6 +38,10 @@ export const buildCompositeFilter = <DbModelType extends CompositeFilterDocument
38
38
  return null;
39
39
  }
40
40
 
41
+ if (queryConstraints.length <= 1) {
42
+ return queryConstraints[0];
43
+ }
44
+
41
45
  return (query as CompositeFilter).operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
42
46
  }
43
47
 
@@ -73,6 +77,11 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
73
77
  if (queryConstraints.length <= 0) {
74
78
  return undefined;
75
79
  }
80
+
81
+ if (queryConstraints.length <= 1) {
82
+ return queryConstraints[0];
83
+ }
84
+
76
85
  return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
77
86
  }, [query]);
78
87
  };
@@ -1,6 +1,17 @@
1
1
  /**
2
2
  * A custom hook that determines if the Firebase authentication state is ready.
3
3
  * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
4
- * @returns {boolean} Indicates whether the authentication state is ready.
4
+ *
5
+ * @group Hook
6
+ *
7
+ * @returns {boolean}
8
+ *
9
+ * @example
10
+ * ```jsx
11
+ * export const MyComponent = () => {
12
+ * const isAuthStateReady = useAuthStateReady();
13
+ * console.log(isAuthStateReady);
14
+ * };
15
+ * ```
5
16
  */
6
17
  export declare const useAuthStateReady: () => boolean;
@@ -3,7 +3,18 @@ import { useCallback, useEffect, useState } from "react";
3
3
  /**
4
4
  * A custom hook that determines if the Firebase authentication state is ready.
5
5
  * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
6
- * @returns {boolean} Indicates whether the authentication state is ready.
6
+ *
7
+ * @group Hook
8
+ *
9
+ * @returns {boolean}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const isAuthStateReady = useAuthStateReady();
15
+ * console.log(isAuthStateReady);
16
+ * };
17
+ * ```
7
18
  */
8
19
  export const useAuthStateReady = () => {
9
20
  const firebaseAuth = useAuth();
@@ -4,7 +4,18 @@ import { useCallback, useEffect, useState } from "react";
4
4
  /**
5
5
  * A custom hook that determines if the Firebase authentication state is ready.
6
6
  * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
7
- * @returns {boolean} Indicates whether the authentication state is ready.
7
+ *
8
+ * @group Hook
9
+ *
10
+ * @returns {boolean}
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * export const MyComponent = () => {
15
+ * const isAuthStateReady = useAuthStateReady();
16
+ * console.log(isAuthStateReady);
17
+ * };
18
+ * ```
8
19
  */
9
20
  export const useAuthStateReady = () => {
10
21
  const firebaseAuth = useAuth();