[英]No Firebase App '[Default] has been created - call firebase.initializeApp()
[英]call firebase.initializeApp() problem on react native
我已经使用这个 npx react-native init --template @react-native-firebase/template MyAwesomeApp 创建了反应应用程序,然后设置了 firebase 一切正常,直到我遇到错误:
没有 Firebase 应用程序“[DEFAULT]”已创建 - 调用 firebase.initializeApp()。
下面是我的 App.js 代码
import React from 'react';
import firestore from '@react-native-firebase/firestore';
const usersCollection = firestore().collection('Food');
function Addfood() {
usersCollection
.add({
color: "White",
name: "None"
})
};
const App = () => {
return (
<View>
<Addfood/>
<Text>Test2</Text>
</View>
);
};
const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});
export default App;
您可以将您的 firebase 逻辑放在一个单独的文件中,而不是将其放在 app.js 中,如果您只是想测试它,我编辑了您的代码并添加了初始化。
import React from 'react';
import firestore,{firebase} from '@react-native-firebase/firestore';
//here add your credentials
firebase.initializeApp({
appId: '',
apiKey: '',
projectId: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: '',
clientId: '',
});
const usersCollection = firestore().collection('Food');
function Addfood() {
usersCollection
.add({
color: "White",
name: "None"
})
};
const App = () => {
return (
<View>
<Addfood/>
<Text>Test2</Text>
</View>
);
};
const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});
export default App;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.