react-query-firebase 3.1.1 → 3.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/dist/react-native/analytics/useAnalytics.d.ts +1 -1
- package/dist/react-native/context/FirebaseContext.d.ts +4 -2
- package/dist/react-native/context/FirebaseContext.js +0 -1
- package/dist/react-native/context/FirebaseContextProvider.d.ts +2 -2
- package/dist/react-native/context/FirebaseContextProvider.js +3 -1
- package/dist/react-native/index.d.ts +1 -0
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/messaging/index.d.ts +4 -0
- package/dist/react-native/messaging/index.js +4 -0
- package/dist/react-native/messaging/useDeleteTokenMutation.d.ts +35 -0
- package/dist/react-native/messaging/useDeleteTokenMutation.js +36 -0
- package/dist/react-native/messaging/useGetTokenMutation.d.ts +48 -0
- package/dist/react-native/messaging/useGetTokenMutation.js +37 -0
- package/dist/react-native/messaging/useMessaging.d.ts +8 -0
- package/dist/react-native/messaging/useMessaging.js +13 -0
- package/dist/react-native/messaging/useOnMessageHandler.d.ts +6 -0
- package/dist/react-native/messaging/useOnMessageHandler.js +15 -0
- package/dist/web/context/FirebaseContext.d.ts +2 -0
- package/dist/web/context/FirebaseContext.js +0 -1
- package/dist/web/context/FirebaseContextProvider.js +3 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/messaging/index.d.ts +4 -0
- package/dist/web/messaging/index.js +4 -0
- package/dist/web/messaging/useDeleteTokenMutation.d.ts +35 -0
- package/dist/web/messaging/useDeleteTokenMutation.js +36 -0
- package/dist/web/messaging/useGetTokenMutation.d.ts +48 -0
- package/dist/web/messaging/useGetTokenMutation.js +37 -0
- package/dist/web/messaging/useMessaging.d.ts +8 -0
- package/dist/web/messaging/useMessaging.js +13 -0
- package/dist/web/messaging/useOnMessageHandler.d.ts +6 -0
- package/dist/web/messaging/useOnMessageHandler.js +15 -0
- package/package.json +21 -19
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Hook to access Firebase analytics from the Firebase context.
|
|
3
3
|
* @returns {any} The analytics object from the Firebase context.
|
|
4
4
|
*/
|
|
5
|
-
export declare const useAnalytics: () => import("@react-native-firebase/analytics").
|
|
5
|
+
export declare const useAnalytics: () => import("@react-native-firebase/analytics").Analytics;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { type ReactNativeFirebase } from "@react-native-firebase/app";
|
|
2
2
|
import { type FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Analytics } from "@react-native-firebase/analytics";
|
|
4
|
+
import { type Messaging } from "@react-native-firebase/messaging";
|
|
4
5
|
import { type FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
5
6
|
import { type FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
6
7
|
export type FirebaseContextValue = {
|
|
7
8
|
auth: FirebaseAuthTypes.Module;
|
|
8
|
-
analytics:
|
|
9
|
+
analytics: Analytics;
|
|
9
10
|
firebase: ReactNativeFirebase.FirebaseApp;
|
|
10
11
|
remoteConfig: FirebaseRemoteConfigTypes.Module;
|
|
11
12
|
firestore: FirebaseFirestoreTypes.Module;
|
|
13
|
+
messaging: Messaging;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* FirebaseContext is a shared context across children that provides access to firebase features
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { ConsentSettings } from "@react-native-firebase/analytics";
|
|
3
3
|
import { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
4
4
|
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
5
|
/**
|
|
@@ -88,7 +88,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
88
88
|
* security_storage: "denied"
|
|
89
89
|
* }
|
|
90
90
|
*/
|
|
91
|
-
consentSettings?:
|
|
91
|
+
consentSettings?: ConsentSettings;
|
|
92
92
|
/**
|
|
93
93
|
* Specifies custom configurations for your Cloud Firestore instance.
|
|
94
94
|
* You must set these before invoking any other methods.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from "react";
|
|
2
2
|
import { connectAuthEmulator, getAuth } from "@react-native-firebase/auth";
|
|
3
|
+
import { getMessaging } from "@react-native-firebase/messaging";
|
|
3
4
|
import { setAnalyticsCollectionEnabled, setConsent, getAnalytics } from "@react-native-firebase/analytics";
|
|
4
5
|
import { getRemoteConfig } from "@react-native-firebase/remote-config";
|
|
5
6
|
import { connectFirestoreEmulator, getFirestore } from "@react-native-firebase/firestore";
|
|
@@ -90,7 +91,8 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
|
|
|
90
91
|
auth: internalAuth,
|
|
91
92
|
analytics: internalAnalytics,
|
|
92
93
|
firestore: internalFirestore,
|
|
93
|
-
remoteConfig: internalRemoteConfig
|
|
94
|
+
remoteConfig: internalRemoteConfig,
|
|
95
|
+
messageing: getMessaging(internalFirebase)
|
|
94
96
|
}), [internalFirebase, internalAuth, internalAnalytics, internalFirestore, internalRemoteConfig]);
|
|
95
97
|
useEffect(() => {
|
|
96
98
|
if (contextValue.analytics) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseDeleteTokenMutationOptions<TContext = unknown> = {
|
|
7
|
+
/**
|
|
8
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
9
|
+
*/
|
|
10
|
+
options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "mutationFn">;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Executes a mutation and deletes token for push notifications
|
|
14
|
+
*
|
|
15
|
+
* @group Hook
|
|
16
|
+
*
|
|
17
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
18
|
+
*
|
|
19
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation result
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```jsx
|
|
23
|
+
* export const MyComponent = () => {
|
|
24
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
25
|
+
* options: {
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // ....
|
|
30
|
+
* mutate();
|
|
31
|
+
* // ....
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDeleteTokenMutation: ({ options }: UseDeleteTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { deleteToken } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and deletes token for push notifications
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate();
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useDeleteTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async () => {
|
|
33
|
+
return await deleteToken(messaging);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseGetTokenMutationValues = {
|
|
7
|
+
/**
|
|
8
|
+
* API key
|
|
9
|
+
*/
|
|
10
|
+
vapidKey: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
15
|
+
export type UseGetTokenMutationOptions<TContext = unknown> = {
|
|
16
|
+
/**
|
|
17
|
+
* Options for useMutation hook excluding mutationFn.
|
|
18
|
+
*/
|
|
19
|
+
options?: Omit<UseMutationOptions<{
|
|
20
|
+
token: string;
|
|
21
|
+
}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>, "mutationFn">;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Executes a mutation and returns token for.current instance
|
|
25
|
+
*
|
|
26
|
+
* @group Hook
|
|
27
|
+
*
|
|
28
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
29
|
+
*
|
|
30
|
+
* @returns {UseMutationResult<{token: string;}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* export const MyComponent = () => {
|
|
35
|
+
* const {mutate} = useGetTokenMutation({
|
|
36
|
+
* options: {
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // ....
|
|
41
|
+
* mutate({vapidKey: 'key'});
|
|
42
|
+
* // ....
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const useGetTokenMutation: ({ options }: UseGetTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<{
|
|
47
|
+
token: string;
|
|
48
|
+
}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { getToken } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and returns token for.current instance
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<{token: string;}, ReactNativeFirebase.NativeFirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useGetTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate({vapidKey: 'key'});
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useGetTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async ({ vapidKey }) => {
|
|
33
|
+
const token = await getToken(messaging, { vapidKey: vapidKey });
|
|
34
|
+
return { token };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FirebaseContext } from "../context/FirebaseContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an instance of firestore bound to the closest context.
|
|
5
|
+
*
|
|
6
|
+
* @group Hook
|
|
7
|
+
*
|
|
8
|
+
* @returns {Messaging}
|
|
9
|
+
*/
|
|
10
|
+
export const useMessaging = () => {
|
|
11
|
+
const { messaging } = useContext(FirebaseContext);
|
|
12
|
+
return messaging;
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { onMessage } from "@react-native-firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to start listening for push notifications.
|
|
6
|
+
*/
|
|
7
|
+
export const useOnMessageHandler = ({ callback }) => {
|
|
8
|
+
const messaging = useMessaging();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = onMessage(messaging, callback);
|
|
11
|
+
return () => {
|
|
12
|
+
unsubscribe();
|
|
13
|
+
};
|
|
14
|
+
}, [messaging, callback]);
|
|
15
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Auth } from "firebase/auth";
|
|
2
2
|
import { Analytics } from "firebase/analytics";
|
|
3
3
|
import { Firestore } from "firebase/firestore";
|
|
4
|
+
import { Messaging } from "firebase/messaging";
|
|
4
5
|
import { FirebaseApp } from "firebase/app";
|
|
5
6
|
import { RemoteConfig } from "firebase/remote-config";
|
|
6
7
|
type FirebaseContextValue = {
|
|
@@ -9,6 +10,7 @@ type FirebaseContextValue = {
|
|
|
9
10
|
firebase: FirebaseApp;
|
|
10
11
|
remoteConfig: RemoteConfig;
|
|
11
12
|
firestore: Firestore;
|
|
13
|
+
messaging: Messaging;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* FirebaseContext is a shared context across children that provides access to firebase features
|
|
@@ -3,6 +3,7 @@ import { browserLocalPersistence, browserSessionPersistence, connectAuthEmulator
|
|
|
3
3
|
import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
|
|
4
4
|
import { getRemoteConfig } from "firebase/remote-config";
|
|
5
5
|
import { connectFirestoreEmulator, initializeFirestore } from "firebase/firestore";
|
|
6
|
+
import { getMessaging } from "firebase/messaging";
|
|
6
7
|
import { initializeApp } from "firebase/app";
|
|
7
8
|
import { FirebaseContext } from "./FirebaseContext.js";
|
|
8
9
|
/**
|
|
@@ -106,7 +107,8 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
106
107
|
auth,
|
|
107
108
|
analytics,
|
|
108
109
|
firestore,
|
|
109
|
-
remoteConfig
|
|
110
|
+
remoteConfig,
|
|
111
|
+
messaging: getMessaging(firebase)
|
|
110
112
|
}), [firebase, auth, analytics, firestore, remoteConfig]);
|
|
111
113
|
useEffect(() => {
|
|
112
114
|
if (contextValue.analytics) {
|
package/dist/web/index.d.ts
CHANGED
package/dist/web/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { FirebaseError } from "firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseDeleteTokenMutationOptions<TContext = unknown> = {
|
|
7
|
+
/**
|
|
8
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
9
|
+
*/
|
|
10
|
+
options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "mutationFn">;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Executes a mutation and deletes token for push notifications
|
|
14
|
+
*
|
|
15
|
+
* @group Hook
|
|
16
|
+
*
|
|
17
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
18
|
+
*
|
|
19
|
+
* @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation result
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```jsx
|
|
23
|
+
* export const MyComponent = () => {
|
|
24
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
25
|
+
* options: {
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // ....
|
|
30
|
+
* mutate();
|
|
31
|
+
* // ....
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDeleteTokenMutation: ({ options }: UseDeleteTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { deleteToken } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and deletes token for push notifications
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseDeleteTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useDeleteTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate();
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useDeleteTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async () => {
|
|
33
|
+
await deleteToken(messaging);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
+
import { FirebaseError } from "firebase/app";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseGetTokenMutationValues = {
|
|
7
|
+
/**
|
|
8
|
+
* API key
|
|
9
|
+
*/
|
|
10
|
+
vapidKey: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
15
|
+
export type UseGetTokenMutationOptions<TContext = unknown> = {
|
|
16
|
+
/**
|
|
17
|
+
* Options for useMutation hook excluding mutationFn.
|
|
18
|
+
*/
|
|
19
|
+
options?: Omit<UseMutationOptions<{
|
|
20
|
+
token: string;
|
|
21
|
+
}, FirebaseError, UseGetTokenMutationValues, TContext>, "mutationFn">;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Executes a mutation and returns token for.current instance
|
|
25
|
+
*
|
|
26
|
+
* @group Hook
|
|
27
|
+
*
|
|
28
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
29
|
+
*
|
|
30
|
+
* @returns {UseMutationResult<{token: string;}, FirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* export const MyComponent = () => {
|
|
35
|
+
* const {mutate} = useGetTokenMutation({
|
|
36
|
+
* options: {
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // ....
|
|
41
|
+
* mutate({vapidKey: 'key'});
|
|
42
|
+
* // ....
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const useGetTokenMutation: ({ options }: UseGetTokenMutationOptions) => import("@tanstack/react-query").UseMutationResult<{
|
|
47
|
+
token: string;
|
|
48
|
+
}, FirebaseError, UseGetTokenMutationValues, unknown>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { getToken } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Executes a mutation and returns token for.current instance
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseGetTokenMutationOptions} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<{token: string;}, FirebaseError, UseGetTokenMutationValues, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useGetTokenMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // ....
|
|
22
|
+
* mutate({vapidKey: 'key'});
|
|
23
|
+
* // ....
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const useGetTokenMutation = ({ options = {} }) => {
|
|
28
|
+
const messaging = useMessaging();
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationKey: ["GET_MESSAGING_TOKEN_MUTATION"],
|
|
31
|
+
...options,
|
|
32
|
+
mutationFn: async ({ vapidKey }) => {
|
|
33
|
+
const token = await getToken(messaging, { vapidKey: vapidKey });
|
|
34
|
+
return { token };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { FirebaseContext } from "../context/FirebaseContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an instance of firestore bound to the closest context.
|
|
5
|
+
*
|
|
6
|
+
* @group Hook
|
|
7
|
+
*
|
|
8
|
+
* @returns {Messaging}
|
|
9
|
+
*/
|
|
10
|
+
export const useMessaging = () => {
|
|
11
|
+
const { messaging } = useContext(FirebaseContext);
|
|
12
|
+
return messaging;
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { onMessage } from "firebase/messaging";
|
|
3
|
+
import { useMessaging } from "./useMessaging.js";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to start listening for push notifications.
|
|
6
|
+
*/
|
|
7
|
+
export const useOnMessageHandler = ({ callback }) => {
|
|
8
|
+
const messaging = useMessaging();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = onMessage(messaging, callback);
|
|
11
|
+
return () => {
|
|
12
|
+
unsubscribe();
|
|
13
|
+
};
|
|
14
|
+
}, [messaging, callback]);
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"@react-native-firebase/crashlytics": "^23.x.x",
|
|
12
12
|
"@react-native-firebase/firestore": "^23.x.x",
|
|
13
13
|
"@react-native-firebase/installations": "^23.x.x",
|
|
14
|
+
"@react-native-firebase/messaging": "^23.x.x",
|
|
14
15
|
"@react-native-firebase/remote-config": "^23.x.x",
|
|
15
16
|
"@tanstack/react-query": "^5.x.x",
|
|
16
17
|
"firebase": "^11.x.x || ^12.x.x",
|
|
@@ -21,34 +22,35 @@
|
|
|
21
22
|
},
|
|
22
23
|
"description": "This module offers react hooks to work with Firebase on react-native and web platforms",
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@eslint-community/eslint-plugin-eslint-comments": "^4.
|
|
25
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
|
|
25
26
|
"@react-native-firebase/analytics": "^23.5.0",
|
|
26
27
|
"@react-native-firebase/app": "^23.5.0",
|
|
27
|
-
"@react-native-firebase/auth": "^23.
|
|
28
|
-
"@react-native-firebase/crashlytics": "^23.
|
|
29
|
-
"@react-native-firebase/firestore": "^23.
|
|
30
|
-
"@react-native-firebase/installations": "^23.
|
|
31
|
-
"@react-native-firebase/
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
28
|
+
"@react-native-firebase/auth": "^23.8.8",
|
|
29
|
+
"@react-native-firebase/crashlytics": "^23.8.8",
|
|
30
|
+
"@react-native-firebase/firestore": "^23.8.8",
|
|
31
|
+
"@react-native-firebase/installations": "^23.8.8",
|
|
32
|
+
"@react-native-firebase/messaging": "^23.8.8",
|
|
33
|
+
"@react-native-firebase/remote-config": "^23.8.8",
|
|
34
|
+
"@tanstack/react-query": "^5.90.21",
|
|
35
|
+
"@types/react": "^19.2.14",
|
|
36
|
+
"eslint": "^9.39.4",
|
|
35
37
|
"eslint-config-prettier": "^10.1.8",
|
|
36
38
|
"eslint-plugin-import": "^2.32.0",
|
|
37
|
-
"eslint-plugin-jest": "^29.
|
|
38
|
-
"eslint-plugin-jsonc": "^2.21.
|
|
39
|
-
"eslint-plugin-prettier": "^5.5.
|
|
39
|
+
"eslint-plugin-jest": "^29.15.0",
|
|
40
|
+
"eslint-plugin-jsonc": "^2.21.1",
|
|
41
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
40
42
|
"eslint-plugin-react": "^7.37.5",
|
|
41
43
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
42
44
|
"firebase": "^12.7.0",
|
|
43
45
|
"husky": "^9.1.7",
|
|
44
|
-
"lint-staged": "^16.
|
|
45
|
-
"prettier": "^3.
|
|
46
|
-
"react": "^19.2.
|
|
47
|
-
"typedoc": "^0.28.
|
|
48
|
-
"typedoc-plugin-markdown": "^4.
|
|
46
|
+
"lint-staged": "^16.4.0",
|
|
47
|
+
"prettier": "^3.8.1",
|
|
48
|
+
"react": "^19.2.4",
|
|
49
|
+
"typedoc": "^0.28.17",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
49
51
|
"typedoc-vitepress-theme": "^1.1.2",
|
|
50
52
|
"typescript": "^5.9.3",
|
|
51
|
-
"typescript-eslint": "^8.
|
|
53
|
+
"typescript-eslint": "^8.57.0",
|
|
52
54
|
"vitepress": "^1.6.4"
|
|
53
55
|
},
|
|
54
56
|
"homepage": "https://github.com/vpishuk/react-query-firebase",
|
|
@@ -91,5 +93,5 @@
|
|
|
91
93
|
"docs:build": "vitepress build docs",
|
|
92
94
|
"docs:preview": "vitepress preview docs"
|
|
93
95
|
},
|
|
94
|
-
"version": "3.
|
|
96
|
+
"version": "3.2.0"
|
|
95
97
|
}
|