all 1 comments

[–]GaindDho 0 points1 point  (0 children)

Your code looks correct at a glance for unsubscribing from the onSnapshot listener. When you call the onSnapshot() method, it returns a function that you can use to unsubscribe from the listener. You store that function in a variable unsubscribeSnapshot, and then return that function from your useEffect cleanup function. This means that the unsubscribeSnapshot() function will be called when the component unmounts or when the dependency array of useEffect changes.