RTK Query useLazyQuery and tag invalidation #4978
Unanswered
blake-logik
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a function that would take in a list of ids and make individual requests for each one BUT reference the cache if it already exists there. As far as I can tell, the only way to do this is to use the useLazyQuery function with the preferCacheValue set to true. Something like this:
This works fine, HOWEVER, if I invalidate tags associated to this query, the cache is still used. It isn't until the global "stale" time is reached that they refetch. If I understand correctly this is expected, as invalidating the cache only triggers changes to subscribed hooks (not lazy). It took me a while to find the documentation that mentions that 1. lazy does not use the cache 2. but there is an argument to override that behavior 3. but it doesn't work with tag invalidation. This felt very unintuitive.
Is there any work around for this use case? Would it ever make sense to have the cache store an "invalid" key (or any type of invalidation information that could be used to derive an "invalid" state), so that one could control when the lazy queries are triggered?
Beta Was this translation helpful? Give feedback.
All reactions