Powered By GitBook
Removing a listener from firestorm
In react, if you attach a listener for realtime updates when a component mounts, you'd need to remove it when the component amounts.
Failing to do so could raise an error if you delete that item and there's a listener that is still associated with it.
1
let unsub = db.collection('cities').onSnapshot(() => {
2
​
3
});
4
​
5
​
6
// ...
7
​
8
// Stop listening for changes
9
unsub();
Copied!

In React hooks

if using React hooks, you use useEffect and return a function to do the clean up. See the React docs for more details on the equivalent syntax to componentWillUnmount https://reactjs.org/docs/hooks-effect.html#example-using-hooks-1​
TODO: Add code example
Last modified 1yr ago
Copy link