簡體   English   中英

firebase.database(app) arg 需要一個 FirebaseApp 實例或未定義

[英]firebase.database(app) arg expects a FirebaseApp instance or undefined

我正在嘗試將數據設置到 firebase 上的實時數據庫。我使用了以下代碼。 我正在傳遞我的數據庫名稱以及 url 中的區域,但仍然出現此錯誤。 有沒有人知道代碼有什么問題。

錯誤“firebase.database(app) arg 需要一個 FirebaseApp 實例或未定義。確保提供的 arg 是一個 Firebase 應用程序實例;或者沒有參數以使用默認的 Firebase 應用程序。” 我還初始化了 firebase 配置。

我在獲取數據時也遇到了同樣的問題。 在此處輸入圖像描述

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'});

        });

    };

};

這是我的代碼和輸出

作為 Firebase 實時數據庫文檔,

在此處輸入圖像描述

所以,代碼將是:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM