79607346

Date: 2025-05-05 17:07:23
Score: 0.5
Natty:
Report link

This is how to solve the issue on the messaging module example.

  1. Use this type of the import:
import { getMessaging, requestPermission, setBackgroundMessageHandler, onMessage, getToken, onNotificationOpenedApp, getInitialNotification, subscribeToTopic, hasPermission } from '@react-native-firebase/messaging';
  1. Remove all messaging() calls and use imported methods directly. All of them (except getMessaging) require first additional argument: messaging instance.

Old code:

messaging().getInitialNotification().then(message => this.catchMessage(message));
var token = await messaging().getToken();

New code:

const messagingInstance = getMessaging();

getInitialNotification(messagingInstance).then(message => this.catchMessage(message));
var token = await getToken(messagingInstance);

Big example code is given here: https://github.com/invertase/react-native-firebase/issues/8282#issuecomment-2760400136

Reasons:
  • Blacklisted phrase (1): how to solve
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Denis