Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useDocument and useCollection in the same component causes useCollection to return an empty array #105

Open
rolznz opened this issue Mar 27, 2021 · 6 comments

Comments

@rolznz
Copy link

rolznz commented Mar 27, 2021

This causes the collection to return an empty array

const { data: document } = useDocument<IChallenge>('challenges/challenge-1');
const { data: collection } = useCollection<IChallenge>('challenges');
console.log('document', document, 'collection', collection);

Result:
document {id: 'abc'…},  collection []

However, the following seems to work fine (just swapping around the calls)

const { data: collection } = useCollection<IChallenge>('challenges');
const { data: document } = useDocument<IChallenge>('challenges/challenge-1');
console.log('document', document, 'collection', collection);

Result:
document {id: 'abc'…}, collection (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

@rolznz
Copy link
Author

rolznz commented Mar 27, 2021

Note: I actually use a filter on the collection query, so there is a valid usecase for this. I have just made the simplest way to reproduce the issue.

@solkpolk
Copy link

const {data:user, error:errorUser} = useDocument(users/${uid}, {listen:false}) const {data:niftys} = useCollection("nifty", { where: ['userId', "==", uid], listen: true })

@rolznz
Copy link
Author

rolznz commented Apr 13, 2021

const {data:user, error:errorUser} = useDocument(users/${uid}, {listen:false}) const {data:niftys} = useCollection("nifty", { where: ['userId', "==", uid], listen: true })

I don't think this is the solution. I shouldn't be forced to listen to changes.

@345ml
Copy link

345ml commented Dec 20, 2021

I am suffering from the same phenomenon.
In my case, it seems to be happening in Android cases where the where condition, etc. is changed dynamically.

If I revalidate it after some time, it goes away, but it seems to need about 5 seconds to go by.

@rolznz
Copy link
Author

rolznz commented Dec 20, 2021

@345ml

I have started a complete rewrite of this library as it is no longer maintained and there are many bugs. If you are interested it's here: https://github.com/rolznz/swr-firestore (Note that the syntax is different in order to make use of the latest version of firebase)

@345ml
Copy link

345ml commented Jan 20, 2022

@rolznz
Alright.
Good job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants