I'm creating an application with react
and I currently need to retrieve some data from database
using the firebase
library, so I've created a module that performs the configuration:
File: firebase.js
import firebase from 'firebase';
const config = {
apiKey: "XYZ",
authDomain: "XYZ.firebaseapp.com",
databaseURL: "https://XYZ.firebaseio.com",
projectId: "XYZ",
storageBucket: "XYZ.appspot.com",
messagingSenderId: "123"
};
export default firebase.initializeApp(config);
Inside another module I include the configuration module and start using it:
import React, { Component } from 'react'
import firebase from '../../firebase'
export default class MeuComponent extends Component {
componentDidMount () {
console.log('did mount');
var dbRef = firebase.database().ref().child('apiDataReference');
dbRef.on('value', snap => console.log(snap.val()));
}
...
}
When the component is rendered I see the did mount
used in the console.log()
, however I get the following error then:
unreachable code after return statement Learn more