Problem in unsubscribe of useSubscription react hook
See original GitHub issueWhen react component unmounts
, the useSubscription
hook doesn’t unsubscribe
stream in server side.
const TestComponent = () => {
const { loading, error, data } = useSubscription(SUBSCRIPTION);
useEffect(() => {
return () => {
// unsubscribe here
};
}, []);
return <div>TestComponent</div>;
};
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:15 (2 by maintainers)
Top Results From Across the Web
Is it possible to cancel Graphql subscriptions? - General
@alexb the useSubscription hook will automatically unsubscribe any started subscriptions, when the component using it is unmounted.
Read more >React unsubscribe from RxJS subscription in useEffect
The issue is that unsubscribe is not actually a function. It's a method on an subscription object. Because of this, the first value...
Read more >useSubscription | Relay
API reference for useSubscription, a React hook used to subscribe and unsubscribe from a subscription.
Read more >Cancel / Unsubscribe GraphQL Subscription - Vimal Selvam
This post shows on how to cancel / unubscribe the active GraphQL subscription using Apollo Client package with React.
Read more >Using Subscriptions with React - GQty
Hook designed to be used for GraphQL Subscriptions. ... Subscribe on-demand; Automatic unsubscribe on component unmount; Automatic updates on cache changes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@benjamn Hey, I have the same problem
Upgrading to 3.7.0-beta.1 did not help 😦
I was about to read through the test files to check whether there are tests set up (to confirm that
unsubscribe
is being called on subscriptions when they ought to be dropped), but then I opened this: https://github.com/apollographql/apollo-client/blob/a565fd5036b23810f59b49affc69a36cdb434a55/src/core/__tests__/QueryManager/index.tsAnd I saw it has 5,881 lines.
And I quietly backed away.