T
TanStack3y ago
correct-apricot

Invalidate query doesn't work

im trying to invalidate query : queryClient.invalidateQueries({ queryKey: ["user"] }); As I understand this should trigger getQuery for "user" key and update state from API. Then somewhere in Layout i have:
const { vendor, profileImage, name } = queryClient.getQueryData([
"user",
]) as User;
const { vendor, profileImage, name } = queryClient.getQueryData([
"user",
]) as User;
Which should react to changes in user key and rerender updated layout. But this doesnt. invalidateQueries does not trigger
useQuery({
queryKey: ["user"],
queryFn: getUser,
})
useQuery({
queryKey: ["user"],
queryFn: getUser,
})
What Im missing?
2 Replies
correct-apricot
correct-apricotOP3y ago
Im using queryClient from useQueryClient(), Im not creating another queryClient by new QueryClient()
typical-coral
typical-coral3y ago
getQueryData doesn't create a subscription. You want useQuery

Did you find this page helpful?