react-query-firebase 3.1.0 → 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.
Files changed (33) hide show
  1. package/dist/react-native/analytics/useAnalytics.d.ts +1 -1
  2. package/dist/react-native/context/FirebaseContext.d.ts +4 -2
  3. package/dist/react-native/context/FirebaseContext.js +0 -1
  4. package/dist/react-native/context/FirebaseContextProvider.d.ts +2 -2
  5. package/dist/react-native/context/FirebaseContextProvider.js +4 -2
  6. package/dist/react-native/index.d.ts +1 -0
  7. package/dist/react-native/index.js +1 -0
  8. package/dist/react-native/messaging/index.d.ts +4 -0
  9. package/dist/react-native/messaging/index.js +4 -0
  10. package/dist/react-native/messaging/useDeleteTokenMutation.d.ts +35 -0
  11. package/dist/react-native/messaging/useDeleteTokenMutation.js +36 -0
  12. package/dist/react-native/messaging/useGetTokenMutation.d.ts +48 -0
  13. package/dist/react-native/messaging/useGetTokenMutation.js +37 -0
  14. package/dist/react-native/messaging/useMessaging.d.ts +8 -0
  15. package/dist/react-native/messaging/useMessaging.js +13 -0
  16. package/dist/react-native/messaging/useOnMessageHandler.d.ts +6 -0
  17. package/dist/react-native/messaging/useOnMessageHandler.js +15 -0
  18. package/dist/web/context/FirebaseContext.d.ts +2 -0
  19. package/dist/web/context/FirebaseContext.js +0 -1
  20. package/dist/web/context/FirebaseContextProvider.js +3 -1
  21. package/dist/web/index.d.ts +1 -0
  22. package/dist/web/index.js +1 -0
  23. package/dist/web/messaging/index.d.ts +4 -0
  24. package/dist/web/messaging/index.js +4 -0
  25. package/dist/web/messaging/useDeleteTokenMutation.d.ts +35 -0
  26. package/dist/web/messaging/useDeleteTokenMutation.js +36 -0
  27. package/dist/web/messaging/useGetTokenMutation.d.ts +48 -0
  28. package/dist/web/messaging/useGetTokenMutation.js +37 -0
  29. package/dist/web/messaging/useMessaging.d.ts +8 -0
  30. package/dist/web/messaging/useMessaging.js +13 -0
  31. package/dist/web/messaging/useOnMessageHandler.d.ts +6 -0
  32. package/dist/web/messaging/useOnMessageHandler.js +15 -0
  33. 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").FirebaseAnalyticsTypes.Module;
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 FirebaseAnalyticsTypes } from "@react-native-firebase/analytics";
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: FirebaseAnalyticsTypes.Module;
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,4 +1,3 @@
1
- "use client";
2
1
  import { createContext } from "react";
3
2
  /**
4
3
  * 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 { FirebaseAnalyticsTypes } from "@react-native-firebase/analytics";
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?: FirebaseAnalyticsTypes.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";
@@ -38,7 +39,7 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
38
39
  analytics_storage: false,
39
40
  functionality_storage: false,
40
41
  personalization_storage: false,
41
- security_storage: false,
42
+ security_storage: "denied",
42
43
  ...consentSettings
43
44
  });
44
45
  }, [consentSettings, internalFirebase]);
@@ -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) {
@@ -3,3 +3,4 @@ export * from "./analytics/index.js";
3
3
  export * from "./auth/index.js";
4
4
  export * from "./firestore/index.js";
5
5
  export * from "./remoteConfig/index.js";
6
+ export * from "./messaging/index.js";
@@ -3,3 +3,4 @@ export * from "./analytics/index.js";
3
3
  export * from "./auth/index.js";
4
4
  export * from "./firestore/index.js";
5
5
  export * from "./remoteConfig/index.js";
6
+ export * from "./messaging/index.js";
@@ -0,0 +1,4 @@
1
+ export * from "./useDeleteTokenMutation.js";
2
+ export * from "./useGetTokenMutation.js";
3
+ export * from "./useMessaging.js";
4
+ export * from "./useOnMessageHandler.js";
@@ -0,0 +1,4 @@
1
+ export * from "./useDeleteTokenMutation.js";
2
+ export * from "./useGetTokenMutation.js";
3
+ export * from "./useMessaging.js";
4
+ export * from "./useOnMessageHandler.js";
@@ -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,8 @@
1
+ /**
2
+ * Returns an instance of firestore bound to the closest context.
3
+ *
4
+ * @group Hook
5
+ *
6
+ * @returns {Messaging}
7
+ */
8
+ export declare const useMessaging: () => import("@react-native-firebase/messaging").Messaging;
@@ -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,6 @@
1
+ /**
2
+ * Custom hook to start listening for push notifications.
3
+ */
4
+ export declare const useOnMessageHandler: ({ callback }: {
5
+ callback: <T>(value: T) => unknown;
6
+ }) => void;
@@ -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
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  import { createContext } from "react";
3
2
  /**
4
3
  * 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) {
@@ -3,3 +3,4 @@ export * from "./analytics/index.js";
3
3
  export * from "./auth/index.js";
4
4
  export * from "./firestore/index.js";
5
5
  export * from "./remoteConfig/index.js";
6
+ export * from "./messaging/index.js";
package/dist/web/index.js CHANGED
@@ -3,3 +3,4 @@ export * from "./analytics/index.js";
3
3
  export * from "./auth/index.js";
4
4
  export * from "./firestore/index.js";
5
5
  export * from "./remoteConfig/index.js";
6
+ export * from "./messaging/index.js";
@@ -0,0 +1,4 @@
1
+ export * from "./useDeleteTokenMutation.js";
2
+ export * from "./useGetTokenMutation.js";
3
+ export * from "./useMessaging.js";
4
+ export * from "./useOnMessageHandler.js";
@@ -0,0 +1,4 @@
1
+ export * from "./useDeleteTokenMutation.js";
2
+ export * from "./useGetTokenMutation.js";
3
+ export * from "./useMessaging.js";
4
+ export * from "./useOnMessageHandler.js";
@@ -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,8 @@
1
+ /**
2
+ * Returns an instance of firestore bound to the closest context.
3
+ *
4
+ * @group Hook
5
+ *
6
+ * @returns {Messaging}
7
+ */
8
+ export declare const useMessaging: () => import("@firebase/messaging").Messaging;
@@ -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,6 @@
1
+ /**
2
+ * Custom hook to start listening for push notifications.
3
+ */
4
+ export declare const useOnMessageHandler: ({ callback }: {
5
+ callback: <T>(value: T) => unknown;
6
+ }) => void;
@@ -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.5.0",
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.7.0",
28
- "@react-native-firebase/crashlytics": "^23.7.0",
29
- "@react-native-firebase/firestore": "^23.7.0",
30
- "@react-native-firebase/installations": "^23.7.0",
31
- "@react-native-firebase/remote-config": "^23.7.0",
32
- "@tanstack/react-query": "^5.90.15",
33
- "@types/react": "^19.2.7",
34
- "eslint": "^9.39.2",
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.11.2",
38
- "eslint-plugin-jsonc": "^2.21.0",
39
- "eslint-plugin-prettier": "^5.5.4",
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.2.7",
45
- "prettier": "^3.7.4",
46
- "react": "^19.2.3",
47
- "typedoc": "^0.28.15",
48
- "typedoc-plugin-markdown": "^4.9.0",
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.51.0",
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.1.0"
96
+ "version": "3.2.0"
95
97
  }