react-query-firebase 1.3.1 → 1.3.2

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,6 +1,7 @@
1
1
  import React, { PropsWithChildren } from "react";
2
2
  import { ConsentSettings } from "firebase/analytics";
3
3
  import { RemoteConfigSettings } from "firebase/remote-config";
4
+ import { FirestoreSettings } from "firebase/firestore";
4
5
  import { FirebaseOptions } from "firebase/app";
5
6
  /**
6
7
  * @inline
@@ -71,6 +72,13 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
71
72
  * }
72
73
  */
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;
74
82
  /**
75
83
  * Flag indicating whether Firebase Firestore should be enabled.
76
84
  * @defaultValue `true`
@@ -3,7 +3,7 @@ import { FirebaseContext } from "./FirebaseContext";
3
3
  import { connectAuthEmulator, getAuth } from "firebase/auth";
4
4
  import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
5
  import { getRemoteConfig } from "firebase/remote-config";
6
- import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
6
+ import { connectFirestoreEmulator, initializeFirestore } from "firebase/firestore";
7
7
  import { initializeApp } from "firebase/app";
8
8
  /**
9
9
  * FirebaseContextProvider component configures and provides Firebase services to its children.
@@ -28,7 +28,7 @@ import { initializeApp } from "firebase/app";
28
28
  * };
29
29
  * ```
30
30
  */
31
- export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
31
+ export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
32
32
  const firebase = useMemo(() => {
33
33
  return initializeApp(options);
34
34
  }, [options]);
@@ -44,39 +44,53 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
44
44
  ...consentSettings
45
45
  });
46
46
  }, [consentSettings]);
47
- const contextValue = useMemo(() => {
48
- const value = {};
47
+ const firestore = useMemo(() => {
49
48
  if (firestoreEnabled) {
50
- const firestore = getFirestore(firebase);
49
+ const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
51
50
  if (emulators?.firestore?.host && emulators?.firestore?.port) {
52
- connectFirestoreEmulator(firestore, emulators.firestore.host, emulators.firestore.port);
51
+ connectFirestoreEmulator(localFirestore, emulators.firestore.host, emulators.firestore.port);
53
52
  }
54
- value.firestore = firestore;
53
+ return localFirestore;
55
54
  }
55
+ return null;
56
+ }, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
57
+ const auth = useMemo(() => {
56
58
  if (authEnabled) {
57
- const auth = getAuth(firebase);
59
+ const localAuth = getAuth(firebase);
58
60
  if (emulators?.auth?.host) {
59
- connectAuthEmulator(auth, emulators?.auth?.host, {
61
+ connectAuthEmulator(localAuth, emulators?.auth?.host, {
60
62
  disableWarnings: true
61
63
  });
62
64
  }
63
- value.auth = auth;
65
+ return localAuth;
64
66
  }
67
+ return null;
68
+ }, [emulators?.auth, authEnabled]);
69
+ const analytics = useMemo(() => {
65
70
  if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
66
- const analytics = getAnalytics(firebase);
67
- value.analytics = analytics;
71
+ return getAnalytics(firebase);
68
72
  }
73
+ return null;
74
+ }, [analyticsEnabled, options.measurementId]);
75
+ const remoteConfig = useMemo(() => {
69
76
  if (remoteConfigEnabled && typeof window !== "undefined") {
70
- const remoteConfig = getRemoteConfig(firebase);
77
+ const localRemoteConfig = getRemoteConfig(firebase);
71
78
  if (remoteConfigSettings) {
72
- remoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
73
- remoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
74
- remoteConfig.defaultConfig = remoteConfigDefaults;
79
+ localRemoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
80
+ localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
81
+ localRemoteConfig.defaultConfig = remoteConfigDefaults;
75
82
  }
76
- value.remoteConfig = remoteConfig;
83
+ return localRemoteConfig;
77
84
  }
78
- return { firebase, ...value };
79
- }, [firebase]);
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]);
80
94
  useEffect(() => {
81
95
  if (contextValue.analytics) {
82
96
  setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "docs:build": "vitepress build docs",
61
61
  "docs:preview": "vitepress preview docs"
62
62
  },
63
- "version": "1.3.1"
63
+ "version": "1.3.2"
64
64
  }
@@ -3,7 +3,7 @@ import { FirebaseContext } from "./FirebaseContext";
3
3
  import { connectAuthEmulator, getAuth } from "firebase/auth";
4
4
  import { ConsentSettings, getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
5
5
  import { getRemoteConfig, RemoteConfigSettings } from "firebase/remote-config";
6
- import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
6
+ import { connectFirestoreEmulator, FirestoreSettings, initializeFirestore } from "firebase/firestore";
7
7
  import { FirebaseOptions, initializeApp } from "firebase/app";
8
8
 
9
9
  /**
@@ -78,6 +78,13 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
78
78
  * }
79
79
  */
80
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;
81
88
  /**
82
89
  * Flag indicating whether Firebase Firestore should be enabled.
83
90
  * @defaultValue `true`
@@ -132,7 +139,8 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
132
139
  consentSettings = {},
133
140
  remoteConfigEnabled = true,
134
141
  remoteConfigSettings,
135
- remoteConfigDefaults = {}
142
+ remoteConfigDefaults = {},
143
+ firestoreSettings
136
144
  }) => {
137
145
  const firebase = useMemo(() => {
138
146
  return initializeApp(options);
@@ -151,46 +159,63 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
151
159
  });
152
160
  }, [consentSettings]);
153
161
 
154
- const contextValue = useMemo(() => {
155
- const value: Partial<React.ContextType<typeof FirebaseContext>> = {};
156
-
162
+ const firestore = useMemo(() => {
157
163
  if (firestoreEnabled) {
158
- const firestore = getFirestore(firebase);
164
+ const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
159
165
 
160
166
  if (emulators?.firestore?.host && emulators?.firestore?.port) {
161
- connectFirestoreEmulator(firestore, emulators.firestore.host, emulators.firestore.port);
167
+ connectFirestoreEmulator(localFirestore, emulators.firestore.host, emulators.firestore.port);
162
168
  }
163
169
 
164
- value.firestore = firestore;
170
+ return localFirestore;
165
171
  }
166
172
 
173
+ return null;
174
+ }, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
175
+
176
+ const auth = useMemo(() => {
167
177
  if (authEnabled) {
168
- const auth = getAuth(firebase);
178
+ const localAuth = getAuth(firebase);
169
179
  if (emulators?.auth?.host) {
170
- connectAuthEmulator(auth, emulators?.auth?.host, {
180
+ connectAuthEmulator(localAuth, emulators?.auth?.host, {
171
181
  disableWarnings: true
172
182
  });
173
183
  }
174
- value.auth = auth;
184
+ return localAuth;
175
185
  }
186
+ return null;
187
+ }, [emulators?.auth, authEnabled]);
176
188
 
189
+ const analytics = useMemo(() => {
177
190
  if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
178
- const analytics = getAnalytics(firebase);
179
- value.analytics = analytics;
191
+ return getAnalytics(firebase);
180
192
  }
193
+ return null;
194
+ }, [analyticsEnabled, options.measurementId]);
181
195
 
196
+ const remoteConfig = useMemo(() => {
182
197
  if (remoteConfigEnabled && typeof window !== "undefined") {
183
- const remoteConfig = getRemoteConfig(firebase);
198
+ const localRemoteConfig = getRemoteConfig(firebase);
184
199
  if (remoteConfigSettings) {
185
- remoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
186
- remoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
187
- remoteConfig.defaultConfig = remoteConfigDefaults;
200
+ localRemoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
201
+ localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
202
+ localRemoteConfig.defaultConfig = remoteConfigDefaults;
188
203
  }
189
- value.remoteConfig = remoteConfig;
204
+ return localRemoteConfig;
190
205
  }
191
-
192
- return { firebase, ...value };
193
- }, [firebase]);
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
+ );
194
219
 
195
220
  useEffect(() => {
196
221
  if (contextValue.analytics) {