-
Take the firestore example here (https://stackblitz.com/edit/reactfire-v4-sample), if we change the querying doc path to
and it will be stuck in 'fetching burrito flavor' forever. In some cases, we'd like to determine the request is finished and the document doesn't exist for now. Is there any way we could detect such a condition in reactfire? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @namiwang, in that case the function BurritoTaste() {
// easily access the Firestore library
const burritoRef = doc(useFirestore(), 'tryreactfire', 'burrito');
// subscribe to a document for realtime updates. just one line!
const { status, data } = useFirestoreDocData(burritoRef);
// easily check the loading status
if (status === 'loading') {
return <p>Fetching burrito flavor...</p>;
} else if (data === undefined) {
return <p>Burrito not found!</p>;
}
return <p>The burrito is {data.yummy ? 'good' : 'bad'}!</p>;
} |
Beta Was this translation helpful? Give feedback.
Hi @namiwang, in that case the
data
field of the object returned byuseFirestoreDocData
will beundefined
, andstatus
will besuccess
. This means that ReactFire is actively listening for that document in Firestore, but nothing is there. So you can just add a check: