redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

RTQ: How to unsubscribe from a `useLazyQuery`

Open nichita-pasecinic opened this issue 3 years ago • 4 comments

Hello 👋

In documentation https://redux-toolkit.js.org/rtk-query/usage/usage-without-react-hooks#removing-a-subscription is specified a different way of subscription - un-subscription method for a query, but how to we do it with a hook ?

const [trigger, { data }] = useLazyEnpointQuery();

I cant pass a skip property to useLazyQuery that forces the unsubscription from the query, it can be used only with the useQuery hook. So how can I unsubscribe from a lazy query ?

Thanks for help!

nichita-pasecinic avatar Feb 21 '22 07:02 nichita-pasecinic

Hi, Any updates on it? wouldn't be nice if the useLazyEndpointQuery() returned something like unsubscribe here :

const [trigger, { data, unsubscribe }] = useLazyEnpointQuery();

nichita-pasecinic avatar Mar 16 '22 09:03 nichita-pasecinic

At the moment, the only way to unsubscribe from a lazy query is to start a new one with a different argument or to unmount the component.

It might be a nice to have to have an unsubscribe option, but it's not high in the priorities. PRs against useLazyQuerySubscription are welcome.

phryneas avatar Mar 16 '22 21:03 phryneas

I think the feature is added. rtk useLazyQuery()

bleedingAyush avatar Aug 18 '22 14:08 bleedingAyush

I think the reset would be more important like @phryneas mentions here https://github.com/reduxjs/redux-toolkit/pull/2133#issuecomment-1173164762

I hope this reset feature will gain priority

henkkasoft avatar Nov 02 '22 10:11 henkkasoft