Replies: 1 comment 1 reply
-
I think it is the desired behavior. A change in query key will yield a new cache entry, so initialData is respected. You can make initialData a function and return undefined for keys that are not the key that you want.
as far as I’m aware, initialData respects staleTime. So per default (staleTime: 0), you will get initialData followed by a background refetch. |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
If the initial data is passed directly as an object to the useQuery configuration, then the initial data is also applied whenever the query key is changed. This means that the query function is never called and so the same data is always returned. I would expect that the initial data is only used once for the first query key or if the first query key is passed again.
I'm just wondering if this is the desired behaviour, when using it like:
As a workaround, I pre-populated the QueryCache with an initial query key and data before calling useQuery.
Beta Was this translation helpful? Give feedback.
All reactions