Skip to content

How to determine if the document does not exist at all or it's indeed still 'loading'? #438

Answered by jhuleatt
namiwang asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @namiwang, in that case the data field of the object returned by useFirestoreDocData will be undefined, and status will be success. This means that ReactFire is actively listening for that document in Firestore, but nothing is there. So you can just add a check:

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>Burri…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@namiwang
Comment options

@jhuleatt
Comment options

@atanaskanchev
Comment options

@jhuleatt
Comment options

@jhuleatt
Comment options

Answer selected by namiwang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants