Check if refetch was done manually #6904
Unanswered
moaazassali
asked this question in
Q&A
Replies: 1 comment
-
|
we don't distinguish between kinds of fetches - a query doesn't know what initiated the fetch. So yes, you'd need to do this in user-land. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to show a loading skeleton if the user manually pressed a button which runs
query.refetch(). I am aware thatisRefetchingcan be used, but this flag is also true for other refetches on window focus for example, and I don't to show the loading skeleton on refetches that happen on window focus.The motivation behind this is that a refresh button press from a UX perspective should have a loading indicator, but a refetch on window focus shouldn't show the same loading indicator. This is especially the cases for when the user switches back and forth to the webapp like when copying data to an excel sheet. A manual refresh would show the same loading skeleton as a page refresh for example, while a refetch on window focus would have a small non-blocking loading indicator or nothing at all, which is why it is essential to be able to distinguish between manual and automatic refetches.
I can solve this by setting my own
isManuallyRefetchingflag in a global store which is set totruewhen I callquery.refetch(). Then, I can useuseEffectwithisRefetchingdependency such that it setsisManuallyRefetchingtofalsewhen it becomesfalseas well.However, since I am using the same query in multiple components, this will quickly become messy and I am wondering if it is possible to check if a manual refetch happened with react query only. Or maybe I can add an extension method like
query.manuallyRefetch()for any arbitrary query? But I am not sure how to do that.Beta Was this translation helpful? Give feedback.
All reactions