'React Native Firestore getting data problem
When I try to access the data from a Firestore collection called 'Targets' it returns:
{"_U": 0, "_V": 0, "_W": null, "_X": null}
my firestore item is: item photo
My code:
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, Text, Button, TouchableOpacity } from 'react-native';
import auth from '@react-native-firebase/auth'
import { useNavigation } from '@react-navigation/native';
import MapView, { Circle } from 'react-native-maps';
import * as geolib from 'geolib';
import firestore from '@react-native-firebase/firestore';
export default function MenuScreen() {
const targetData = firestore().collection('Targets').where('isActive', '==', true).get()
console.log(targetData)
}
I tried useState and other hooks but it still returns same data. How can I resolve that?
Solution 1:[1]
.get()
just returns a promise.. you need to continue on to get the data:
firestore().collection("Targets").where("isActive", "==", true)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
https://firebase.google.com/docs/firestore/query-data/queries#web-version-8_3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | John Detlefs |