Reactjs 使用re base在React应用程序和Firebase数据库之间同步状态上的多个属性

Reactjs 使用re base在React应用程序和Firebase数据库之间同步状态上的多个属性,reactjs,firebase,firebase-realtime-database,Reactjs,Firebase,Firebase Realtime Database,当涉及到将react应用程序状态的一个属性与firebase同步时,re-base文档非常清楚: 它表示在组件的componentDidMount方法中使用syncState,如下所示: componentDidMount(){ base.syncState(`shoppingList`, { context: this, state: 'items', asArray: true }); } componentDidMount(){ base.syncSt

当涉及到将react应用程序状态的一个属性与firebase同步时,re-base文档非常清楚:

它表示在组件的componentDidMount方法中使用syncState,如下所示:

componentDidMount(){
  base.syncState(`shoppingList`, {
    context: this,
    state: 'items',
    asArray: true
  });
}
componentDidMount(){
  base.syncState(`shoppingList`, {
    context: this,
    state: 'items'
  });
  base.syncState(`weeklyBudget`, {
    context: this,
    state: 'budget'
  });

}
我想同步两个不同的属性,所以“shoppingList”;和“每周预算”。我试图像这样重复这句话:

componentDidMount(){
  base.syncState(`shoppingList`, {
    context: this,
    state: 'items',
    asArray: true
  });
}
componentDidMount(){
  base.syncState(`shoppingList`, {
    context: this,
    state: 'items'
  });
  base.syncState(`weeklyBudget`, {
    context: this,
    state: 'budget'
  });

}
但控制台只是抛出以下错误:

未捕获错误:对象作为React子对象无效(找到:具有键{}的对象)。如果要呈现子对象集合,请改用数组,或使用React附加组件中的createFragment(object)包装对象。检查
Order
的渲染方法


如何使用re base在React app和Firebase数据库之间同步状态上的多个属性?

如果您在
上下文:this之后立即向对象添加
asArray:true
,您应该会没事的

对我来说就是这样。我自己对这段代码一点也不满意,因为我有七个块连接到不同的端点。另一种方法可能是通过
Promise.all([x,y,z]).then()使用fetch和resolve