react-query-firebase 3.4.0 → 3.5.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useMemo } from "react";
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { connectAuthEmulator, getAuth } from "@react-native-firebase/auth";
|
|
3
3
|
import { getMessaging } from "@react-native-firebase/messaging";
|
|
4
4
|
import { setAnalyticsCollectionEnabled, setConsent, getAnalytics } from "@react-native-firebase/analytics";
|
|
@@ -31,6 +31,7 @@ import { FirebaseContext } from "./FirebaseContext.js";
|
|
|
31
31
|
*/
|
|
32
32
|
export const FirebaseContextProvider = ({ emulators, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings, firestoreDBId = "(default)" }) => {
|
|
33
33
|
const internalFirebase = useMemo(() => getApp(), []);
|
|
34
|
+
const [isFIrestoreReady, setIsFirestoreReady] = useState(false);
|
|
34
35
|
useEffect(() => {
|
|
35
36
|
setConsent(getAnalytics(internalFirebase), {
|
|
36
37
|
ad_personalization: false,
|
|
@@ -44,10 +45,12 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
|
|
|
44
45
|
});
|
|
45
46
|
}, [consentSettings, internalFirebase]);
|
|
46
47
|
useEffect(() => {
|
|
47
|
-
initializeFirestore(internalFirebase, firestoreSettings || {})
|
|
48
|
+
initializeFirestore(internalFirebase, firestoreSettings || {}).then(() => {
|
|
49
|
+
setIsFirestoreReady(true);
|
|
50
|
+
});
|
|
48
51
|
}, [firestoreSettings, internalFirebase]);
|
|
49
52
|
const internalFirestore = useMemo(() => {
|
|
50
|
-
if (firestoreEnabled) {
|
|
53
|
+
if (firestoreEnabled && isFIrestoreReady) {
|
|
51
54
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
52
55
|
connectFirestoreEmulator(getFirestore(internalFirebase), emulators.firestore.host, emulators.firestore.port);
|
|
53
56
|
}
|
|
@@ -55,7 +58,7 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
|
|
|
55
58
|
return localFirestore;
|
|
56
59
|
}
|
|
57
60
|
return null;
|
|
58
|
-
}, [emulators, firestoreEnabled, internalFirebase, firestoreDBId]);
|
|
61
|
+
}, [emulators, firestoreEnabled, internalFirebase, firestoreDBId, isFIrestoreReady]);
|
|
59
62
|
const internalAuth = useMemo(() => {
|
|
60
63
|
if (authEnabled) {
|
|
61
64
|
const localAuth = getAuth(internalFirebase);
|
|
@@ -92,8 +95,9 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
|
|
|
92
95
|
analytics: internalAnalytics,
|
|
93
96
|
firestore: internalFirestore,
|
|
94
97
|
remoteConfig: internalRemoteConfig,
|
|
95
|
-
messaging: getMessaging(internalFirebase)
|
|
96
|
-
|
|
98
|
+
messaging: getMessaging(internalFirebase),
|
|
99
|
+
isFIrestoreReady
|
|
100
|
+
}), [internalFirebase, internalAuth, internalAnalytics, internalFirestore, internalRemoteConfig, isFIrestoreReady]);
|
|
97
101
|
useEffect(() => {
|
|
98
102
|
if (contextValue.analytics) {
|
|
99
103
|
setAnalyticsCollectionEnabled(contextValue.analytics, !!consentSettings?.analytics_storage);
|
|
@@ -108,7 +108,8 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
108
108
|
analytics,
|
|
109
109
|
firestore,
|
|
110
110
|
remoteConfig,
|
|
111
|
-
messaging: getMessaging(firebase)
|
|
111
|
+
messaging: getMessaging(firebase),
|
|
112
|
+
isFIrestoreReady: true
|
|
112
113
|
}), [firebase, auth, analytics, firestore, remoteConfig]);
|
|
113
114
|
useEffect(() => {
|
|
114
115
|
if (contextValue.analytics) {
|
package/package.json
CHANGED