IjzerenHein / firestorter

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

new Document('some/ref'); is not documented #88

Closed gsouf closed 4 years ago

gsouf commented 4 years ago

Tried to work with the document that way:

const doc = new Document('some/ref');

I found that doc.data.someField is always undefined.

Alternatively I tried that:

const doc = new Document('some/ref');
doc.fetch();

Now doc.data.someField has the expected value.

In the doc I couldn't find any example of how to fetch a document. In the readme the document is instancied in a variable but never used.

IjzerenHein commented 4 years ago

I found that doc.data.someField is always undefined.

Have you wrapped your component with observer?

In the doc I couldn't find any example of how to fetch a document. I

Documents and collections are typically fetched automatically. This happens magically when you access data from the render function in your React Component; and your component is wrapped with observer.

You can also choose to use manual fetching. In that case you can indeed call fetch yourself.

In the readme the document is instancied in a variable but never used.

Could you show me code sample that is wrong?

Which doc

gsouf commented 4 years ago

Hi @IjzerenHein the example I mentioned is the one from the readme.

SoI found that indeed it's working properly without fetch when we use an observer.

I got fooled because usage the fetch method causesdocument.isLoading to become true, but autofetching does not. Also autofetching without the obersver causes document.data.name to be undefined in my render method and thus document.data.something was throwing errors

IjzerenHein commented 4 years ago

Yes, nothing happens when you don't have your component wrapped with observer.