[英]FireStore in React-Native
您好我一直在尝试从 React-native App 访问 Firestore
我尝试过的代码
import firebase from '@react-native-firebase/app'
import firestore from '@react-native-firebase/firestore';
import * as Actions from '../../../StateManager/Actions/ActionTypes'
export function getVersion() {
return async (dispatch) => {
/// Method 1
firestore().collection('Versions').get().then(querySnapshot => {
console.log('Snapshot: ' + querySnapshot)
return null
});
/// Method 2
firestore().collection('Versions').get()
.then(querySnapshot => {
console.log(querySnapshot);
console.log(querySnapshot._docs);
})
}
}
我没有工作
配置完成
npm install --save @react-native-firebase/app
npm install —save @react-native-firebase/firestore
in React Appcd iOS/ && pod install
它在 iOS App 中安装了与 Firebase 和 Firestore 相关的所有依赖项调试控制台信息:在下面调用我的 getVersion() 时进入调试模式
我经历了很多关于堆栈的问题无法得到任何肯定 output
包含的库:
React-Navigation, Redux, redux-thunk, Firebase, Firestore
我的商店和 redux 已正确配置和 Screen.js(我称之为的根屏幕已正确连接到 Redux 和商店)
下面我称之为
componentDidMount() {
this.props.getVersion()
if (Platform.OS === 'android') {
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)
}
}
FireStore 结构:
FireStore 规则:
在这里,我根据我的研发更新答案
我可以从 Firestore Collection 获取版本和状态
下面的更新可能会帮助其他语法困难的人
export function getVersion(versionID) {
return async (dispatch) => {
try {
/// For Real Time
firestore().collection('Versions').onSnapshot(querySnapshot => {
querySnapshot.forEach(doc => {
if (doc.exists) {
const { version, status } = doc.data()
}
});
});
/// For One Time
firestore().collection('Versions').get().then(querySnapshot => {
querySnapshot.forEach(doc => {
if (doc.exists) {
const { version, status } = doc.data()
}
});
});
} catch (error) {
console.log("*** Firebase - error setting document", { error });
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.