[英]firebase.database(app) arg expects a FirebaseApp instance or undefined
I'm trying to set data to my realtime database on firebase. I have used the following code.我正在尝试将数据设置到 firebase 上的实时数据库。我使用了以下代码。 I am passing my database name as well as the region in my url still getting this error.
我正在传递我的数据库名称以及 url 中的区域,但仍然出现此错误。 Is there anyone who know's what is wrong with the code.
有没有人知道代码有什么问题。
Error "firebase.database(app) arg expects a FirebaseApp instance or undefined.Ensure the arg provided is a Firebase app instance; or no args to use the default Firebase app."
错误“firebase.database(app) arg 需要一个 FirebaseApp 实例或未定义。确保提供的 arg 是一个 Firebase 应用程序实例;或者没有参数以使用默认的 Firebase 应用程序。” I have also initialised the firebase config.
我还初始化了 firebase 配置。
Also I am getting the same problem while fetching data.我在获取数据时也遇到了同样的问题。
import {EMPLOYEE_UPDATE,EMPLOYEE_CREATE,} from './types';
import database from '@react-native-firebase/database';
import auth from '@react-native-firebase/auth';
import { firebase } from '@react-native-firebase/app';
import { Actions } from 'react-native-router-flux';
export const employeeUpdate = ({prop,value}) => {
return {
type: EMPLOYEE_UPDATE,
payload: {prop,value},
};
};
export const employeeCreate = ({name,phone,shift}) => {
const {currentUser} = auth();
return (dispatch) =>{
*const ref = database(
'https://managerproject-8924c-default-rtdb.asia-southeast1.firebasedatabase.app/')
.ref(`/users/${currentUser.uid}/employees`);
console.log(ref);
ref.set({name,phone,shift})
.then(()=> {*
console.log('Data set.');
dispatch({type: EMPLOYEE_CREATE });
Actions.employeeList({type: 'reset'});
});
};
};
As Firebase realtime database documentation,作为 Firebase 实时数据库文档,
So, the code will be:所以,代码将是:
import { firebase } from '@react-native-firebase/database';
firebase
.app()
.database('https://managerproject-8924c-default-rtdb.asia-southeast1.firebasedatabase.app/'))
.ref(`/users/${currentUser.uid}/employees`)
.set({name,phone,shift})
.then(() => console.log('Data set.'))
.catch((error) => console.log(error));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.