Reputation: 779
Upon pushing some data to firebase in react native I get the following error that my firebase database URL is undefined. I am using the android emulator here. Maybe I am missing something I need to push to firebase in my android build gradle file?
I am currently also using firebase auth for this app it it does work perfectly fine but I had to modify the android build gradle. I'm wondering if this could be a similar issue? If so does anyone know what I need to add?
I'm new to react-native sorry :(
Below is my config and my firebase app initialization
sendNoteToDatabase = () => {
const firebaseConfig = {
apiKey: 'my api key',
authDomain: '*********-37824.firebaseapp.com',
databaseURL: 'https://******-37824.firebaseio.com/',
projectId: '******-23288'
}
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
const note = {
title: "this.state.title",
who: "this.state.who",
time: "this.state.time"
}
firebase.database().ref('Users/').set(note).then((data) => {
//success callback
console.log('data ', data)
}).catch((error) => {
//error callback
console.log('error ', error)
})
}
I have checked the URL and I am using a realtime database. I'm not sure if this is an issue with my code structure or a problem with android?
Upvotes: 0
Views: 223
Reputation: 779
using Franks Advice I was able to solve it by initializing the firebase app using the componentDidMount hook
componentDidMount(){
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
}
Upvotes: 1