【发布时间】:2019-04-04 16:58:06
【问题描述】:
所以我尝试做的很简单:从 Cloud Firestore 接收数据。
我有以下代码:
import React from 'react';
import firebase from "react-native-firebase";
export default class newsFeed extends React.Component {
constructor() {
this.ref = firebase.firestore().collection('keys')
}
async load(id) {
const doc = await this.ref.doc(id).get()
if (doc.exists) {
return doc.data()
}
}
}
我收到一个错误:'无法设置未定义的属性'ref'。
我该如何解决它,有什么问题?
【问题讨论】:
-
使用 Lamba 函数 ( => )。普通函数不继承 this 上下文。
标签: javascript firebase react-native google-cloud-firestore