react-firehooks
Version:
Lightweight dependency-free collection of React hooks for Firebase
15 lines (14 loc) • 774 B
JavaScript
import { getToken } from "firebase/messaging";
import { useGet } from "../internal/useGet.js";
/**
* Returns the messaging token. The token never updates.
* @param messaging Firebase Messaging instance
* @param options Options to configure how the token will be fetched
* @returns Token, loading state, and error
* - value: Messaging token; `undefined` if token is currently being fetched, or an error occurred
* - loading: `true` while fetching the token; `false` if the token was fetched successfully or an error occurred
* - error: `undefined` if no error occurred
*/
export function useMessagingToken(messaging, options) {
return useGet(messaging, (m) => getToken(m, options === null || options === void 0 ? void 0 : options.getTokenOptions), () => true);
}