Skip to content

How can I get uid of all documents if I use useFirestoreCollectionData hook ? #257

Answered by jhuleatt
catrawalkar asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @catrawalkar , useFirestoreCollectionData accepts a config object that allows you to add an id field to each object in the array it returns. The sample shows how this is done:

const animals = useFirestoreCollectionData(query, { idField: 'id' });

This will add an id key to every result. The returned objects will look like this:

[
    {
        commonName: 'Giraffe',
        id: 'theDocumentId' // the key is `id` because we set `idField` to "id"
    }
]

It looks like the reference is missing this information. Sorry about that! Any chance you have a moment to create a PR for that? Otherwise I can add it :)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jamesdaniels
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #257 on December 10, 2020 00:34.