react-query-firebase 2.0.0-rc5 → 2.0.0-rc6
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.
|
@@ -15,4 +15,4 @@ export type UseCollectionReferenceOptions<AppModelType extends FirebaseFirestore
|
|
|
15
15
|
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
16
16
|
* @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
|
|
17
17
|
*/
|
|
18
|
-
export declare const useCollectionReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<AppModelType
|
|
18
|
+
export declare const useCollectionReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<AppModelType>;
|
|
@@ -16,4 +16,4 @@ export type UseDocReferenceOptions<AppModelType extends FirebaseFirestoreTypes.D
|
|
|
16
16
|
*
|
|
17
17
|
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
18
18
|
*/
|
|
19
|
-
export declare const useDocReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.DocumentReference<AppModelType
|
|
19
|
+
export declare const useDocReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { doc } from "@react-native-firebase/firestore";
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo } from "react";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
5
5
|
* Generates a document reference for a specified path or reference in Firestore.
|
|
@@ -14,9 +14,6 @@ import { useFirestore } from "./useFirestore";
|
|
|
14
14
|
* @returns {DocumentReference<AppModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
|
|
15
15
|
*/
|
|
16
16
|
const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
17
|
-
if (!path) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
17
|
return (!reference ? doc(db, path || "", ...(pathSegments || [])) : doc(reference, path, ...(pathSegments || [])));
|
|
21
18
|
};
|
|
22
19
|
/**
|
|
@@ -33,9 +30,7 @@ const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
|
33
30
|
*/
|
|
34
31
|
export const useDocReference = ({ path, reference, pathSegments }) => {
|
|
35
32
|
const db = useFirestore();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, [db, path, reference, pathSegments]);
|
|
40
|
-
return ref.current;
|
|
33
|
+
return useMemo(() => {
|
|
34
|
+
return getDocReference(db, { path, pathSegments, reference });
|
|
35
|
+
}, [db, reference, path, pathSegments]);
|
|
41
36
|
};
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ export const useCollectionReference = <
|
|
|
30
30
|
path,
|
|
31
31
|
reference,
|
|
32
32
|
pathSegments
|
|
33
|
-
}: UseCollectionReferenceOptions<AppModelType>): FirebaseFirestoreTypes.CollectionReference<AppModelType>
|
|
33
|
+
}: UseCollectionReferenceOptions<AppModelType>): FirebaseFirestoreTypes.CollectionReference<AppModelType> => {
|
|
34
34
|
const db = useFirestore();
|
|
35
35
|
|
|
36
36
|
return useMemo(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { doc, FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useMemo } from "react";
|
|
4
4
|
import { useFirestore } from "./useFirestore";
|
|
5
5
|
|
|
6
6
|
export type UseDocReferenceOptions<
|
|
@@ -31,10 +31,6 @@ const getDocReference = <
|
|
|
31
31
|
db: FirebaseFirestoreTypes.Module,
|
|
32
32
|
{ path, pathSegments, reference }: UseDocReferenceOptions<AppModelType>
|
|
33
33
|
) => {
|
|
34
|
-
if (!path) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
34
|
return (
|
|
39
35
|
!reference ? doc(db, path || "", ...(pathSegments || [])) : doc(reference, path, ...(pathSegments || []))
|
|
40
36
|
) as FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
@@ -58,15 +54,10 @@ export const useDocReference = <
|
|
|
58
54
|
path,
|
|
59
55
|
reference,
|
|
60
56
|
pathSegments
|
|
61
|
-
}: UseDocReferenceOptions<AppModelType>): FirebaseFirestoreTypes.DocumentReference<AppModelType>
|
|
57
|
+
}: UseDocReferenceOptions<AppModelType>): FirebaseFirestoreTypes.DocumentReference<AppModelType> => {
|
|
62
58
|
const db = useFirestore();
|
|
63
|
-
const ref = useRef<FirebaseFirestoreTypes.DocumentReference<AppModelType> | null>(
|
|
64
|
-
getDocReference(db, { path, pathSegments, reference })
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
ref.current = getDocReference(db, { path, pathSegments, reference });
|
|
69
|
-
}, [db, path, reference, pathSegments]);
|
|
70
59
|
|
|
71
|
-
return
|
|
60
|
+
return useMemo(() => {
|
|
61
|
+
return getDocReference(db, { path, pathSegments, reference });
|
|
62
|
+
}, [db, reference, path, pathSegments]);
|
|
72
63
|
};
|