Another post shared an example of how to unsubscribe, where the Apollo docs don't. The Apollo docs do mention what subscribeToMore returns...
subscribeToMore
: A function that sets up a subscription.subscribeToMore
returns a function that you can use to unsubscribe.
This does give a hint. It would help to see an example.
the question
Using @apollo/react-hooks
, inside of a useEffect()
and returning the results of the subscribeToMore
, is this the way to unsubscribe on a component unmount?
const { data, error, loading, subscribeToMore } = useQuery(GET_DATA)
useEffect(() => {
const unsubscribe = subscribeToMore(/*...*/)
return () => unsubscribe();
}, [])
return () => unsubscribe();
– Inward