question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to remove subscription?

See original GitHub issue

Hi, probably a dumb question, but I didn’t find the answer for it yet. How do I force unsubscribtion using react hooks?

i.e. I have this functional component

function ({ query, queryType }) {

        const [result] = useSubscription({
            query: query,
        })

        const data = result.data && result.data[queryType];

        useEffect(() => {
            console.log("unsubscribe from previous sub")
        }, [queryType])

        return data ? <Component data={data} /> : <>No data</>
}

I want to unsubscribe from previous subscription, when queryType changes and useEffect is triggered. Is there a way to do it?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
svkiorcommented, Jun 29, 2020

@JoviDeCroock tomorrow we will extract the peace of our current project into separate repo and I will provide the link in this issue

btw in appolo-client there is no problem with unsubscribe, but appolo client has performance issues

1reaction
JoviDeCroockcommented, Jun 26, 2020

Hey @vicsnow

There are no dumb questions šŸ˜„ , so on useQuery and useSubscription we have a property called pause that can be passed as an option, similar to how you’re passing query at this time.

Let’s say you want to pause when queryType is not ā€œsubā€ then we can do:

function ({ query, queryType }) {

        const [result] = useSubscription({
            query: query,
            pause: queryType !== 'sub',
        })

        const data = result.data && result.data[queryType];

        return data ? <Component data={data} /> : <>No data</>
}

Now the subscription will be torn down until you unpause it.

Linearly, if your query is dependent on variables it will unsubscribe and resubscribe to the new variables when you change them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If you want to cancel a subscription from Apple - Apple Support
Open the Settings app. Ā· Tap your name. Ā· Tap Subscriptions. The Subscriptions button in Settings on iPhone. Ā· Tap the subscription. Ā·...
Read more >
Cancel, pause, or change a subscription on Google Play
On your Android device, go to your subscriptions in Google Play. Select the subscription you want to cancel. Tap Cancel subscription. Follow the...
Read more >
Here's How to Cancel Subscriptions You Forgot About
Cancel the subscriptions by emailing the service providers. If this proves elusive then go through your bank statements going back for 12 monthsĀ ......
Read more >
How to cancel Adobe trial or subscription
How to cancel your trial or subscription Ā· Select Manage plan for the plan you want to cancel. Select Manage plan or View...
Read more >
Cancel subscriptions | Stripe Documentation
Cancel subscriptions Ā· From the customer account page or the subscription details page, click the overflow menu (. ) Ā· Choose when to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found