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

Add possibility to manually unsubscribe from useLazyQuery #2055

Open damianborowy opened this issue 3 years ago • 10 comments

Related to issue #2055

damianborowy avatar Mar 17 '22 12:03 damianborowy

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1a40475a12501d518b703ec8fad2cc570386a130:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
reduxjs/redux-toolkit Configuration
@examples-action-listener/counter Configuration

codesandbox-ci[bot] avatar Mar 17 '22 12:03 codesandbox-ci[bot]

✅ Deploy Preview for redux-starter-kit-docs ready!

🔨 Explore the source changes: 1a40475a12501d518b703ec8fad2cc570386a130

🔍 Inspect the deploy log: https://app.netlify.com/sites/redux-starter-kit-docs/deploys/6234eb2c12d4cf0008f84be1

😎 Browse the preview: https://deploy-preview-2133--redux-starter-kit-docs.netlify.app

netlify[bot] avatar Mar 17 '22 12:03 netlify[bot]

We just did a grooming of PRs and discussed this: would you be okay to to a PR for a reset method instead that unsubscribed and set the query hook back to isUninitialized?

It feels inconsistent to us that after unsubscribing, the query state will still stay in the component for another 60 seconds - or even forever, if another component is still using it.

Or do you have a good use case that would only make sense with unsubscribe, but not with reset?

phryneas avatar Jul 03 '22 20:07 phryneas

We just did a grooming of PRs and discussed this: would you be okay to to a PR for a reset method instead that unsubscribed and set the query hook back to isUninitialized?

It feels inconsistent to us that after unsubscribing, the query state will still stay in the component for another 60 seconds - or even forever, if another component is still using it.

Or do you have a good use case that would only make sense with unsubscribe, but not with reset?

This is exactly what I am looking for I think.

I am using useLazyQuery with query params given by user. The API response is HTTP ERROR 422 when the user input is incorrectly formed. UI will show modal of the error and then I want to recover without unmounting the component. So I would want to get rid of the isError state and the user could modify the input and trigger the query again.

Is this possible somehow already? And if not, did I understood correctly that this PR (when unsubscribe is extended as reset) will enable this kind of usage?

henkkasoft avatar Nov 02 '22 10:11 henkkasoft

@henkkasoft it will not remove the value, just unsubscribe from it. It will be removed after 60 second if no other component uses it.

Maybe you are giving isError too much importance here?
As it sounds "there is an error from the server" will 100% be true until the data is sent to the server without a 422 - so maybe you just need an additional local state to control that message?

phryneas avatar Dec 22 '22 09:12 phryneas

Hi, I see that there was no activity on this PR for a while now. Is this still pending? I would be happy to take over this PR and implement the above mentioned reset method @damianborowy @henkkasoft

stchristian avatar Jan 17 '24 09:01 stchristian

@stchristian yeah, no one has looked at this in a year. Might be best to re-create it and file a new PR with the updates

markerikson avatar Jan 17 '24 16:01 markerikson

@markerikson Before starting this feature, I would suggest adding a skip parameter instead of reset method, similar to useQuery() that would work the same way setting the hook to uninitialized. This way the query stays consistent with the existing interface.

stchristian avatar Jan 17 '24 17:01 stchristian