I am using firestore onSnapshot methods in a React Native app on several different sets of data in my app, and for the most part they all appear to work fine. However, after a period of time, perhaps after the app is put into background and re-awakened, the onSnapshot methods stop updating the data.
It is as if they have switched off. Sometimes they seem to stop working just after a period of time, without the app being backgrounded.
If I call the methods again then they start working again, but that seems to defeat the object of using them, I may as well just use normal get() methods and call them when I need.
Surely someone else has experienced this and can help?
答案 0 :(得分:0)
发生错误时,Firebase将调用(可选)第二个回调,您可以将其传递给onSnapshot
或简单的get
之类的函数。例如
const coleccionRef = database.ref('test');
coleccionRef.on('value', snapshot => {
snapshot.val();
}, error => {
console.error(error);
});
您可以检查该错误以了解问题所在。