I'm trying to stop listening to Firestore onSnapshot from other function.
I can get Firebase data, But I can't access this unsubscribe();
How can i fix this?
let unsucscribe;
useEffect(() => {
unsubscribe = db.collection('room')
.where('joinUser', 'array-contains-any', [10])
.onSnapshot((res) => {
// do something...
});
}, []);
function unsubscribeFirestore() {
unsubscribe(); // throws an error that unsubscribe is not a function.
}
unsubscribeFirestore();