Next.js - initialData from server, staleTime and queryKey #3210
-
I have an interface that shows products and above that a smaller section with promoted products for currently selected category. My query key looks like this: I tried to solve this by setting Expected result:
Am I missing something or is this not a use case that's valid for react-query? I'm pretty sure I can work around it but it seems like a potentially overlooked feature. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
changes in query key will switch to that cache entry, and if that entry has fresh data, that one will be taken without refetch, so that is expected. if you change to a category that does not yet have data, you should get a hard loading state. please keep in mind that when providing
if I change from id 1 to id 2, id 2 will also get that initial Data. combined with staleTime, it will result in a "no-fetch" scenario. solutions are:
now, only todo with id 1 will get the initial data, others don't.
|
Beta Was this translation helpful? Give feedback.
changes in query key will switch to that cache entry, and if that entry has fresh data, that one will be taken without refetch, so that is expected. if you change to a category that does not yet have data, you should get a hard loading state.
please keep in mind that when providing
initialData
, it will be passed to all query keys:if I change from id 1 to id …