IjzerenHein / firestorter

Use Google Firestore in React with zero effort, using MobX 🤘
http://firestorter.com
MIT License
378 stars 50 forks source link

Fetch single document and keep listeners #97

Closed RWOverdijk closed 4 years ago

RWOverdijk commented 4 years ago

I have a list of products, and I have product details. When I go to the product details I'd like to fetch only that specific product. I know I can use Document to fetch a single document, but I need a query. And I also need to have listeners.

So: how can I fetch a single document by query, and have it updated when it changes in firestore?

Update: I figured out I can use query to fetch a document, and then use that ID to create a new Document with mode set to 'on' or 'auto'.

But that doesn't seem to update the document when changes are made in the firebase console

IjzerenHein commented 4 years ago

I'm not sure I fully understand what your asking here..

But I do think the concept of reactive paths & queries might be useful here. It allows you to create a document or collection and have the path or query update, depending on the content of another document.

const doc = new Document('bar/mybar');

const col = new Collection('foos', {
  query: ref => ref.where('bar', '==', doc.data.bar)
});
RWOverdijk commented 4 years ago

It was silly. I solved it with a new doc and it does listen for changes.