首页 文章

Rebase / Redux / Firebase React数据没有输入

提问于
浏览
0

尝试从Firebase 3.x.x获取数据表以与我的React应用程序同步 . 据我所知,这是同步这两个州最受欢迎的图书馆 . 括号内填入适当的数据 .

App.js:

componentDidMount() {

 var base = Rebase.createClass({
   apiKey: "[API Key]",
   authDomain: "[app-name].firebaseapp.com",
   databaseURL: "https://[my-app].firebaseio.com",
   storageBucket: "[app-name].appspot.com",
 })
 base.syncState(`records`, {
       context: this,
       state: 'records',
       asArray: true
     })
}

我打电话的时候

console.log(this.props.state.records)

我得到一个空数组(在state.js中初始化的数组)我在firebase中的数据如下所示:

https://[app-name].firebaseio.com/

[app-name]{
  records[
    record_1{
     id: 0
     description: "this is a record"
    }
    record_2{
     id: 1
     description: "this is another record"
    }
  ]
}

编辑:我不认为它与身份验证有关 . 在database.rules.sjon中将read和write设置为true并没有产生任何结果 .

编辑:Firebase显示带宽使用情况 .

1 回答

  • 0

    解:

    所以数据实际上是从那里开始的 . 我最初在render()方法中查询它 . 当我创建一个按钮来触发查询this.state.records的类方法时,数据显示出来 .

    所以这意味着 state is not initialized until the JSX return block inside the render method . 似乎有点奇怪但是嘿,现在我知道了 .

相关问题