reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.71k stars 1.17k forks source link

RTQ: How to unsubscribe from a `useLazyQuery` #2055

Open nichita-pasecinic opened 2 years ago

nichita-pasecinic commented 2 years ago

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 commented 2 years ago

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

const [trigger, { data, unsubscribe }] = useLazyEnpointQuery();
phryneas commented 2 years ago

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.

bleedingAyush commented 2 years ago

I think the feature is added. rtk useLazyQuery()

henkkasoft commented 1 year ago

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