I am getting my document data back and storing it in state, but when I try to render it, I am only getting the first item. I notice when I refresh the app, I can see the other items briefly. Not sure why my mapping isn't rendering all the data.
const [tickets, setTickets] = useState([]);
useEffect(() => {
GetTickets();
}, []);
console.log(tickets);
const db = getFirestore();
const colRef = collection(db, "Tickets");
function GetTickets() {
getDocs(colRef).then((snapshot) => {
let tickets = [];
snapshot.docs.forEach((doc) => {
tickets.push({ ...doc.data(), id: doc.id });
setTickets(tickets);
});
});
}
return (
<View style={GlobalStyles.container}>
<Text>Previous tickets</Text>
{tickets.map((ticket) => (
<Text key={ticket.id}>{ticket.form.TicketNumber}</Text>
))}
</View>
);