i am new to react native ,i am trying to fetch the data from my firebase database. i am trying to list out name and age from my firestore collection,
here is my code:
const HomeNurse=({ navigation }) => {
const [users, setUsers] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [isLoading, setIsLoading] = useState(false);
const getUsers = async () => {
let result = [];
const querySnapshot = await getDocs(collection(db, "MyCollection"));
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>" , doc.data());
result.push(doc.data());
});
setUsers([...result]);
};
useEffect(() => {
getUsers();
}, []);
const renderItem = ({ item }) => {
return (
<View>
<View>
<Text>{`${item.name}`}</Text>
<Text>{`${item.age}`}</Text>
</View>
</View>
);
};
const renderLoader = () => {
return isLoading ? (
<View style={styles.loaderStyle}>
<ActivityIndicator size="large" color="#aaa" />
</View>
) : null;
};
const loadMoreItem = () => {
setCurrentPage(currentPage + 1);
};
return (
<View>
<StatusBar backgroundColor="#000" />
<FlatList
data={users}
renderItem={renderItem}
keyExtractor={(item) => item.id}
ListFooterComponent={renderLoader}
onEndReached={loadMoreItem}
onEndReachedThreshold={0} />
</View>
);
};
the output is just a blank screen with a warning:
Possible Unhandled promise rejection id:0
at the terminal:
[Unhandled promise rejection: TypeError: (0, _firebase.collection) is not a function. (In '(0, _firebase.collection)(_firebase.db, "MyCollection")', '(0, _firebase.collection)' is undefined)]