简体   繁体   English

firebase.database(app) arg 需要一个 FirebaseApp 实例或未定义

[英]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.

相关问题 firebase.database 不是 function 为什么我在反应本机应用程序中收到此错误? - firebase.database is not a function why I am getting this error in react native app? 当我使用 firebase.database().goOnline(); 我得到一个错误 - when i use firebase.database().goOnline(); I get an error Function.database 和 Firebase.database 有什么区别? 什么时候使用一个而不是另一个? - What is the difference between Function.database and Firebase.database? When to use one over the other? firebase 实时数据库未定义 function - firebase realtime database undefined function firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.storage 不是 function,firbase.storge() 方法不起作用也试试 firebaseApp.storage - firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.storage is not a function , firbase.storge() method not work also try firebaseApp.storage Firebase 模拟器设置:getFirestore() 或 getFirestore(firebaseApp)? - Firebase emulator setup: getFirestore() or getFirestore(firebaseApp)? firebase.initializeApp() 与 FirebaseApp.initializeApp() - firebase.initializeApp() vs FirebaseApp.initializeApp() Firebase 标准事件 | 应用实例限制 - Firebase Standard Events | App Instance Limit Firebase 模拟器 - Spring 启动 - 名称为 [DEFAULT] 的 FirebaseApp 不存在 - Firebase Emulator - Spring boot - FirebaseApp with name [DEFAULT] doesn't exist 为什么我的 Firebase 数据库的某些属性未定义? - Why are some properties of my Firebase database undefined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM