![](/img/trans.png)
[英]firebase.database is not a function why I am getting this error in react native app?
[英]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.