【发布时间】:2017-10-22 19:53:14
【问题描述】:
【问题讨论】:
标签: firebase react-native google-cloud-firestore react-native-firebase
【问题讨论】:
标签: firebase react-native google-cloud-firestore react-native-firebase
虽然库可能存在需要调查的问题,但您的代码通常是错误的。 React 组件中的状态应该是在更改时会导致重新渲染的数据。您不需要将您的集合分配给状态,这可以作为类属性来完成。此外,使用构造函数和 componentWillMount 是错误的,因为它们本质上是相同的——虽然我不知道它如何在内部处理这两种情况。
你的代码最好这样工作:
constructor() {
super();
this.ref = firebase.firestore().collection('users');
}
componentDidMount() {
this.ref.add({ name: 'moo' });
}
【讨论】:
我有同样的错误。请创建名为“用户”的集合并添加一个虚拟文档。那就试试吧。
【讨论】: