[英]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.在 react native 中将一些数据推送到 firebase 时,我收到以下错误,即我的 firebase 数据库 URL 未定义。 I am using the android emulator here.
我在这里使用 android 模拟器。 Maybe I am missing something I need to push to firebase in my android build gradle file?
也许我错过了我需要在我的 android 构建 gradle 文件中推送到 firebase 的东西?
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.我目前也在为这个应用程序使用 firebase auth 它确实工作得很好,但我不得不修改 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 :(我是 react-native 的新手抱歉:(
Below is my config and my firebase app initialization下面是我的配置和我的 firebase 应用程序初始化
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.我已经检查了 URL,我正在使用实时数据库。 I'm not sure if this is an issue with my code structure or a problem with android?
我不确定这是我的代码结构的问题还是 android 的问题?
using Franks Advice I was able to solve it by initializing the firebase app using the componentDidMount hook使用 Franks Advice 我能够通过使用 componentDidMount 钩子初始化 firebase 应用程序来解决它
componentDidMount(){
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.