I created a new React Native project and I'm using rnfirebase.io Cloud Messaging. The documentation says to use it like in this example and that's how I'm using it: Doc
But I have warning message in Chrome DevTools
index.js:38 This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: Please use
getApp()
instead.
Bellow my code here; index.js
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';
AppRegistry.registerComponent(appName, () => App);
messaging()
.onMessage(async notification => {
/*
Code goes here
*/
});
messaging()
.setBackgroundMessageHandler(async remoteMessage => {
/*
Code goes here
*/
});
What is the correct use? Why this document showing old version usage example
I created a new React Native project and I'm using rnfirebase.io Cloud Messaging. The documentation says to use it like in this example and that's how I'm using it: Doc
But I have warning message in Chrome DevTools
index.js:38 This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22 Please use
getApp()
instead.
Bellow my code here; index.js
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';
AppRegistry.registerComponent(appName, () => App);
messaging()
.onMessage(async notification => {
/*
Code goes here
*/
});
messaging()
.setBackgroundMessageHandler(async remoteMessage => {
/*
Code goes here
*/
});
What is the correct use? Why this document showing old version usage example
Share Improve this question edited Mar 12 at 21:39 Hasan ABLAK asked Mar 12 at 9:06 Hasan ABLAKHasan ABLAK 1011 silver badge7 bronze badges 2- On Stack Overflow, please don't show pictures of text and code. Copy the text into the question itself and format it so that it's easy to read, copy, and search. You can edit the question to correct this using the edit link at the bottom. – Doug Stevenson Commented Mar 12 at 12:44
- ok sir i added. – Hasan ABLAK Commented Mar 12 at 21:39
1 Answer
Reset to default 1It seems your code is using the namespaced API, but the latest React Native firebase docs requires you to migrate to the modular API.
update your index.js
file to use the new getApp()
method instead of calling messaging()
directly.
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { getApp } from 'firebase/app';
import { getMessaging, onMessage } from '@react-native-firebase/messaging';
const firebaseApp = getApp();
const messaging = getMessaging(firebaseApp);
onMessage(messaging, async (notification) => {
console.log('Received foreground notification:', notification);
});
messaging.setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Received background notification:', remoteMessage);
});
AppRegistry.registerComponent(appName, () => App);