Replies: 2 comments 2 replies
-
I think in this case we should also think about ['todos']
['todos', 'settings']
['todos', 'detail', { id: 1 }]
queryClient.setQueryDefaults(['todos'], { staleTime: 5000 })
queryClient.setQueryDefaults(['todos', 'detail'], { cacheTime: 10000 }] I do not necessarily want Also given the above, should we add a possibility to |
Beta Was this translation helpful? Give feedback.
-
I agree that the current behaviour of query defaults is strange. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This was already previously discussed in:
and @GLabat then also added a dev-level warning if multiple defaults are found in v4:
I don't think the current implementation is ideal. Consider the following query keys:
it would be nice if I could set different defaults for multiple layers of granularity. For example, I might want to have all todo details to have a certain
staleTime
, but I want everything todo related to usesuspense
. So I'd do:turns out this doesn't really work because only the first matching default value is set, which would be the suspense one. It's also weird that the order of calls to
setQueryDefaults
matter.What I would expect is all matching defaults to be reduced together with a simple object spread into one object. So for all my details, that would be:
of course, if the same default is set on two different calls to
setQueryDefaults
, we would still apply it by order (last one overwriting previously set ones). It would be nice to know about specificity, but I don't think thats sensible.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions