-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeScreen.js
32 lines (28 loc) · 924 Bytes
/
HomeScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, { useState, useEffect } from "react";
import { View, Text, FlatList, Button } from "react-native";
import { collection, getDocs } from "firebase/firestore";
import db from "../utils/firebase";
const HomeScreen = ({ navigation }) => {
const [renters, setRenters] = useState([]);
useEffect(() => {
const fetchRenters = async () => {
const querySnapshot = await getDocs(collection(db, "renters"));
const rentersList = querySnapshot.docs.map(doc => ({ ...doc.data(), id: doc.id }));
setRenters(rentersList);
};
fetchRenters();
}, []);
return (
<View>
<FlatList
data={renters}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<Text>{item.name}: {item.phone}</Text>
)}
/>
<Button title="Add Renter" onPress={() => navigation.navigate("AddRenter")} />
</View>
);
};
export default HomeScreen;