I'm building a simple page where I want to render all items from FireStore documents. However, I do not understand what exactly FireStore provides. Is it a promise, object or something different?
Standard functon uses doc.data() to get the information. Can somebody explain why it happens? What exactly doc.data() does?
db.collection("cities").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
});
But why it has to be with
console.log(doc.id, " => ", doc.data());
This is just a way to print, with console.log()
, the id and field values (through data()
) of each Firestore DocumentSnapshot
. As explained here, console.log()
can take as parameters "a list of JavaScript objects to output". "The string representations of each of these objects are appended together in the order listed and output".
Now to solve your error, you should do as follows (untested):
db.collection('teamMember').get()
.then(querySnapshot => {
querySnapshot.docs.map(doc => { return <TeamCard name={doc.Name} position={doc.position} text={doc.text} src={doc.url} /> });
});
because the map()
method is a method of an Array
, and a Firestore querySnapshot
is not an array. By calling the docs
method, you get an Array, that you can use with map()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With