简体   繁体   中英

react native firebaseURL not found

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?

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);
    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM