Replies: 1 comment
-
|
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 find myself in situations (such as initializing forms) where I would like to skip caching entirely. To achieve this I have for example implemented the following wrapper for
useQuery
:Basically, the hook adds a unique key suffix for the query to make it "isolated" to make sure that other hooks don't mess up with the cache. I could for example have a custom hook
useUser
that is used in two separate mounted components: one wants to utilize cache, other doesn't:I have previously worked a lot with Apollo Client which provides a fetch policy option to define the cache behavior. For example, to skip cache entirely, I could set the fetch policy as
network-only
. I find the similar option useful for React Query as well. At least to have similar fetch policies as Apollo Client'scache-and-network
(as far as I understand, this is how React Query works at the moment),network-only
(skip cache, only use the query function to get the data),cache-only
(only use cache data, never use the query function to get the data).The "network" part of the naming is perhaps a bit off because React Query isn't strictly only for network fetching. But I find the idea extremely useful.
Beta Was this translation helpful? Give feedback.
All reactions