1
votes

Recently started integrating Firebase in my React Native project.

I am using the official Firebase release: https://www.npmjs.com/package/firebase

However when I check the documentation there isn't any specific documentation for react-native only for like typescript etc.

I tried to simply use this on my main page:

import firebase from 'firebase'
var config = {
  apiKey: "xxxxxxxxxxxxxxxxxxxxxxxx",
  authDomain: 'https://xxxxxxxxx.firebaseapp.com/',
  databaseURL: 'https://xxxxxxxxx.firebaseio.com',
  messagingSenderId: 'xxxxxxxxxx',
  debug: true
}
// ini the firebase component
const firebaseRef = firebase.initializeApp(config)
export default class App extends React.Component {
componentDidMount(){
    firebase.messaging().getToken()
        .then((token) => {
        console.warn(token);
    });
}
}

However this simple thing just returns an error:

TypeError: undefined is not a function ( evaluating '_firebase2.default.messaging()')

How could I abord the integration of Firebase Cloud Messaging to just receive notififcations.

1

1 Answers

0
votes

You may not have initalised your app, it should look something like this :

const configurationOptions = {
debug: true
};

const Firebase = firebase.initializeApp(configurationOptions);

https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html