简体   繁体   中英

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. I am passing my database name as well as the region in my url still getting this error. 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." I have also initialised the firebase config.

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,

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM