How to invalidate query in T3?

Hello, how can i invalidate query in TRPC like that?
const user = await api.user.getMe.query();
const user = await api.user.getMe.query();
When its query, but it does not have any queryKey, revalidate or something like that.. Im using T3 Stack with nextjs. Thanks!
7 Replies
cje
cje13mo ago
you cant invalidate query because its not being cached anywhere
cje
cje13mo ago
useUtils | tRPC
useUtils is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useUtils helpers than what we provide her...
Bartholomeas
BartholomeasOP13mo ago
I mean useQuery, wrong snippet, sorry:
const user = api.user.getMe.useQuery();
const user = api.user.getMe.useQuery();
i can use refetch on that but i cannot pass any keys or something to useQuery?
cje
cje13mo ago
did you read the page i linked
Bartholomeas
BartholomeasOP13mo ago
i've send snippet before i started reading. Now i saw that, thanks! cowbiggy as i can see i cannot force server TRPC request to refetch? Or ill just need to revalidate the route with nextjs?
cje
cje13mo ago
yea in server components theres nothing to invalidate clientside because youre sending Basically Html
ejoo
ejoo12mo ago
const utils = api.useUtils();
utils.user.getMe.invalidate();
const utils = api.useUtils();
utils.user.getMe.invalidate();
Want results from more Discord servers?
Add your server