T
TanStack•13mo ago
cloudy-cyan

Best practice to invalidate useSuspenseQuery

I use tanstack router and try to use the pattern of ensureQueryData and useSuspenseQuery. The query works so far great, but now trying to use queryClient.invaldiateQueries does not seem to behave the same way useQuery was working. How would I invalidate client side the useSuspenseQuery by provided queryKey? Thanks
4 Replies
other-emerald
other-emerald•13mo ago
Why doesn't it work the same (it should)
cloudy-cyan
cloudy-cyanOP•13mo ago
Oh, thanks for pointing it out! I am using graqhql-codegen with react-query plugin and just realised after you wrote, that the plugin distinct between:
queryKey: useUserQuery.getKey()
and
queryKey: useSuspenseUserQuery.getKey()
queryKey: useUserQuery.getKey()
and
queryKey: useSuspenseUserQuery.getKey()
I was using the useUserQuery key on invalidation which is simply wrong key, after updating it everything works as expected. Thanks for clarifying it
other-emerald
other-emerald•13mo ago
always those generators 😅
cloudy-cyan
cloudy-cyanOP•13mo ago
yeah.. its a love-hate relationship.. but I haven't found anything comparable in terms of completeness

Did you find this page helpful?