Florin Cristi
Florin Cristi

Reputation: 41

Firestore onSnapshot() returns null

I have this code :

 firestore()
    .collection('messages')
    .where('conversationString', '==', convString)
    .where('timestamp', '>', maxTimestamp).onSnapshot(onUpdate);

The problem is onUpdate's parameter is null.

const onUpdate = async results => {
    // results is null
};

What can be the problem?

Upvotes: 0

Views: 1712

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598708

The snapshot listener takes two arguments: first the snapshots, second any errors. Only one of these arguments will have a value. So most likely you are getting an error from the SDK.

I highly recommend keeping the documentation handy, and using the examples in there as the basis for your code. From there:

function onResult(QuerySnapshot) {
  console.log('Got Users collection result.');
}

function onError(error) {
  console.error(error);
}

firestore().collection('Users').onSnapshot(onResult, onError);

Upvotes: 6

Related Questions