【问题标题】:Rebase/Redux/Firebase + React data not piping inRebase/Redux/Firebase + React 数据不输入
【发布时间】:2016-08-16 21:06:28
【问题描述】:

尝试从 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 正在显示带宽使用情况。

【问题讨论】:

  • 你确定不应该是console.log(this.state.records)吗?

标签: reactjs firebase redux firebase-realtime-database rebase


【解决方案1】:

解决方案:

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

这意味着在渲染方法中的 JSX 返回块之前不会初始化状态。似乎有点奇怪,但嘿,现在我知道了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 2018-11-07
    • 2020-08-04
    • 2020-01-30
    相关资源
    最近更新 更多