Should queryCache/queryClient clear trigger a refetch? #1363
Replies: 5 comments 12 replies
-
Calling refetchQueries after should do the trick |
Beta Was this translation helpful? Give feedback.
-
@aaronjensen I think Regarding your use case: When the user clicks logout, I would probably call At least that is how I would do it: clear the cache when the user logs out, rather than after they have logged in ... |
Beta Was this translation helpful? Give feedback.
-
I still think the best way is to clear on logout before the new auth components are mounted. This emulates a new entry into the app. The other way would be to loop over all the queries in the cache and remove the ones that have no active observers, then refetch all queries that are active. |
Beta Was this translation helpful? Give feedback.
-
Ah. So why not just setQueryData(key, undefined) and refetch?
Tanner Linsley
…On Dec 7, 2020, 8:48 PM -0700, Aaron Jensen ***@***.***>, wrote:
@tannerlinsley thanks, but see my previous response to @TkDodo. Clearing on logout is a separate thing that won't help because I actually have a query even in the signed out scenario (to see if the user is signed in).
What I want is to be able to clear a query's data while still having its observers maintained and have it refetch essentially as if it was a brand new query.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
I've opened a PR with rough support for It still needs tests and documentation, but I don't have enough time right now to do those. Hopefully this is enough to get people started and finish the job. If ya'll can get it done relatively quickly, it can come out in the main v3 release. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It appears that when calling
clear()
onqueryCache
(v2) orqueryClient
(v3) if a query is active, it will not be refetched until the component that has theuseQuery
is rerendered. This was very surprising--I would have expected it to clear all data and then immediately refetch (complete withisLoading = true
). As far as I can tell, there's no way easy to do that right now. Is there supposed to be a way to do this?My use case is that I have a top level query for the user session, which is effectively null (or an error) when the user is not signed in. Once the user is signed in, I want to clear the query cache and let that refetch in order to get the current user's session (I also want to clear all other queries so that they can be refetched anew for the newly current user).
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions