Reputation: 101
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
Upvotes: 0
Views: 20
Reputation: 2039
It 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);
Upvotes: 0