【发布时间】:2018-12-06 11:01:20
【问题描述】:
这是我第一次使用 react-native 开发 Android 应用。
当我从firestore 检索一些数据时,我尝试使用 async/await,但是当我添加单词 await 时,应用程序崩溃并且不再启动。
正如您在我的 package.json 文件中看到的那样,我使用 react-native-firebase 库。
这是我的组件中不起作用的部分:
componentDidMount() {
this.getAccountFromFirestore(this.props.user);
}
getAccountFromFirestore = async user => {
const accounts = await firebase
.firestore()
.collection('accounts')
.get();
this.setState({ loading: false });
};
这是我的 package.json,如果有用的话
{
"name": "myapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"ios": "react-native run-ios",
"android": "react-native run-android"
},
"dependencies": {
"native-base": "^2.8.1",
"react": "16.6.1",
"react-native": "0.57.6",
"react-native-firebase": "^5.1.1",
"react-native-navigation": "^1.1.493",
"react-native-vector-icons": "^6.1.0",
"react-redux": "^5.1.1",
"redux": "^4.0.1"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.49.2",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}
【问题讨论】:
-
尝试使用 .then() 承诺
-
如果您不介意,请在此处与我们分享您的错误消息(最好是堆栈跟踪)。
标签: javascript react-native google-cloud-firestore