将firebase集成到react app中时出错

时间:2018-01-25 03:29:23

标签: reactjs firebase firebase-realtime-database

我在尝试构建我的反应应用时遇到此错误。自构建破坏以来唯一改变的是我尝试将firebase数据库添加到应用程序。我试图以与我正在使用的教程相同的方式实现它。

×
REBASE: Rebase.createClass failed. Expected an initialized firebase or firestore database object.
▶ 3 stack frames were collapsed.
./src/base.js
C:/Dev/React/my-app/src/base.js:3
  1 | import Rebase from 're-base';
  2 | 
> 3 | const base = Rebase.createClass({
  4 |   apiKey: "AIzaSyC1UGLssKKLkKvYRp02zYVpM1-D88czp7I",
  5 |   authDomain: "catch-of-the-day-ethan-fie.firebaseapp.com",
  6 |   databaseURL: "https://catch-of-the-day-ethan-fie.firebaseio.com",

下面的base.js代码,个人信息和API密钥编辑:

import Rebase from 're-base';

const base = Rebase.createClass({
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
});

export default base;

3 个答案:

答案 0 :(得分:2)

请检查此指南以解决问题。

https://coderjourney.com/tutorials/how-to-integrate-react-with-firebase/

确保使用上述参考文献中提到的正确的库版本语法。

答案 1 :(得分:1)

你去吧

import Rebase from 're-base'
import firebase from 'firebase'

const config = {
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
  messagingSenderId: "SOME_MESSAGING_SENDER_ID"
}

const app = firebase.initializeApp(config)
const base = Rebase.createClass(app.database())


export default base;

答案 2 :(得分:1)

试试这个,它会起作用:

var Rebase = require('re-base');
var firebase = require('firebase/app');
var database = require('firebase/database');
var app = firebase.initializeApp({
  apiKey: "apiKey",
  authDomain: "projectId.firebaseapp.com",
  databaseURL: "https://databaseName.firebaseio.com",
  storageBucket: "bucket.appspot.com",
  messagingSenderId: "xxxxxxxxxxxxxx"
});
var db = firebase.database(app);
var base = Rebase.createClass(db);