Search code examples
javascriptfirebasereact-nativegoogle-cloud-firestorereact-native-firebase

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?


Solution

  • 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);