2016-06-13 91 views
2

我想在本地做出反應集成火力點。但是我遇到了Firebase的小問題。 這是我的代碼。我也附加了一個屏幕截圖。 我使用反應原生0.27。火力地堡不工作的反應本地

請幫忙。 謝謝

enter image description here

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
    TouchableHighlight, 
    TextInput, 
    ListView 
} from 'react-native'; 

import Firebase from 'firebase'; 

class devdacticFirebase extends Component { 
    constructor(props) { 
    super(props); 
    var itemsRef = new Firebase('https://<myid>.firebaseio.com/items'); 

    this.state = { 
     newTodo: '', 
     dataSource: new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2}) 
    }; 
    } 
    render(){ 
    return(
     <View /> 
    ); 
    } 
} 


AppRegistry.registerComponent('devdacticFirebase',() => devdacticFirebase); 
+0

我使用'NPM如果我沒有記錯的火力地堡3.x版本不安裝火力--save' –

+0

支持React native –

+0

是的,如果它是正確的。這真的很糟糕 –

回答

1

的消息告訴您火力地堡不是構造函數,所以你不能用它new。官方的文檔說明如何初始化您的應用程序:

var firebase = require('firebase'); 

var app = firebase.initializeApp({ 
    apiKey: '<your-api-key>', 
    authDomain: '<your-auth-domain>', 
    databaseURL: '<your-database-url>', 
    storageBucket: '<your-storage-bucket>' 
}); 
+0

謝謝你的幫助。但我只是做喜歡這樣的方式https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html教程。但讓我嘗試一下你的建議 –

+1

顯然firebase 3仍然不能與react-native一起工作。我認爲2.4.2曾經工作過,現在可以使用該版本。那麼你必須像你在你的問題那樣使用它作爲構造函數 –

+0

是的,它是正確的。我沒有重新安裝版本2.4.2,它的工作。感謝專業 –

0

他們改變了文檔中的JS初始化火力項目,所以它會工作在本地做出反應。

保持代碼相同的其餘部分與該替換的構造:

var itemsRef = { 
apiKey: '<your-api-key>', 
authDomain: '<your-auth-domain>', 
databaseURL: '<your-database-url>', 
storageBucket: '<your-storage-bucket>' 
}; 

Firebase.initializeApp(itemsRef);