'getting error in firebase realtime database configuration in react native using expo CLI
I am working on one app in which I need to insert some data into firebase realtime data base first I installed firebase using expo install firebase
here is my code
created one firebase.js file in which everything related to firebase configuration things are there
import * as firebase from 'firebase/app';
import { initializeApp, getApps } from 'firebase/app';
const firebaseConfig = {
apiKey: “…………………..”,
authDomain: “………………”,
databaseURL: “…………”,
projectId: “……………..”,
storageBucket: “………….”,
messagingSenderId: “…………….”,
appId: “……………….”,
measurementId: “…………….”,
};
let fb;
if (getApps.length === 0) {
// initializeApp(firebaseConfig);
fb = firebase.initializeApp(firebaseConfig, 'appname');
}
export default fb;
I am using that fb over here in app.js
import { getDatabase, ref, onValue, set } from 'firebase/database';
import { fb } from '../firebase'
const timeStamp = Math.floor(Date.now() / 1000);
const insertKey = "_" + timeStamp;
const contactsDbRef = fb.app().database().ref('contacts/'+insertKey);
contactsDbRef.set({
name:'abc',
number: '45454545454',
email: '[email protected]',
}).then(() => {
console.log("Data updated")
}).catch(e => console.log(e))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
