-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
invalidateQueries doesn't work when enabled attribute is set to false #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What happens if you set |
Unfortunately, nothing has changed. Doesn't invalidate |
Hi, im using |
disabled and inactive are not the same thing. Disabled queries will never be refetched, except with refetch() returned from useQuery. Documented here: https://react-query.tanstack.com/guides/disabling-queries |
Yeah, thankfully there is only one child component so i passed the refetch
function as a callback prop. Tho, it would be nice to have another prop or
something like `invalidateQueryOnRefetchDisabled` (not good with names).
*Johnathan Angarita Romero*
*Tech Lead & Front-End Developer *
*Development & UX*
El sáb, 8 ene 2022 a las 7:57, Joshua Folorunsho ***@***.***>)
escribió:
… @jsangaritar <https://github.com/jsangaritar>, were you able to find a
way around it?
—
Reply to this email directly, view it on GitHub
<#947 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKLHYXEDVUGJZ5APEJGZ2LUVAYD7ANCNFSM4QRQYE3A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@jsangaritar I'm still wondering what your use-case is where you disable a query but then want to trigger a refetch of that disabled query from another component... it seems like this doesn't work with RQ, but a bit against it. The query will still be disabled after refetch and you won't benefit from smart revalidations ... |
Hi TkDodo I have a use case where I am wanting to load queries and receive items based on a button click and then delete one of those items on the UI. I have set up the enabled:false so that the query retrieves the list of items based on the button press. User actions: Current behavior Discussion So Indeed my understanding this is a bug or a feature that seems counter intuitive as it works without the flag just fine. Workaround If that is not how I should go about this please advise. But in short, this pattern seems natural, my code is almost identical to the OPs original example. |
once you set Hence it is very much on purpose that invalidation skips disabled queries and this will not change. For your case, you might also want to not set enabled to hardcoded false, but to a state value that changes from false to true once you click that button. See also lazy queries |
Hi! Contributing with our use case as well: A query is enabled if the user has logged in, and disabled if logged out (i.e. As there is no option to invalidate the data once it is disabled, the only sane approach was to move the enable-logic to the fetch method, returning the equivalent of invalidated data if the user is logged out, thus replacing the data. This isn't a big headache, but it could also be avoided with an option |
In the case of query is const qc = useQueryClient();
qc.resetQueries([ECacheKey.PROFILE_ME]); Hope it helps someone who has the same problem as me
|
I don't think if there is anyone dumb like me encounters this mistake but I leave it for who does. Apparently wagmi client has the same method import { useQueryClient } from 'wagmi'; instead of import { useQueryClient } from 'react-query'; |
queryCache.invalidateQueries() function doesn't work if the related useQuery definition has { enabled: false } configuration.
Here is the definition of my 'menus'

If I try to create a new 'menu', invalidateQueries works as expected

But if I add a configuration as { enabled: false} as in the below image invalidateQueries function doesn't work

I've spent too many hours on this issue. I changed every other details/configuration but nothing helped. I also tried my other queryKeys other than 'menus' but the problem remains. In my case, it's not a big deal to remove the { enable: false } configuration but is this the expected output ?
React Query - v2.12.1
React Query Developer Tools - v2.3.2
Apart from this issue React Query has been smooth and wonderful. Thanks everyone who contributes this project.
Peace
The text was updated successfully, but these errors were encountered: