-
Notifications
You must be signed in to change notification settings - Fork 408
-
Hi folks,
I have a document ID which is parsed from a URL query. That means that it could be invalid or point to a document that a user doesn't have security rule permissions to read. My solution for this right now is to catch errors when loading the document:
getDoc(doc(db, "Collection", documentId)).catch((error) => handle(error));
I'd like to switch to using useFirestoreDocData because of the very simple API for realtime updates and the efficient caching of listeners. I was hoping that the returned status field would be useful for indentifying cases where the document isn't available (e.g. invalid ID or missing permissions). This is what I wrote:
const { status, data } = useFirestoreDocData(doc(db, 'Collection', documentId));
if (status === 'loading') {
// handle loading
} else if (status === 'error') {
// handle errors
} else {
// display the document
}
This doesn't work and instead I get an uncaught missing permissions error (including for an invalid document ID). So I have two questions I think:
- What is status === 'error' supposed to be used for? I couldn't see anything in the docs or other discussions/issues.
- What is the best way to deal with document reads which may fail? I think I could create an error boundary to catch the error but for my use case that's more boilerplate than just not using reactfire.
Thanks a lot : )
Beta Was this translation helpful? Give feedback.