How do I access onSuccess with TRPC client side?

We can do it with react query quite simply, but i don't see a documentation on it with trpc. if the request is succesful i want to save the data to global state via zustand. I need the onSuccess to do it i believe.
const tickets = trpc.ticketService.getByTenantId.useQuery()
const tickets = trpc.ticketService.getByTenantId.useQuery()
this does not work
React.useEffect(() => {
if (tickets.data) {
setTickets(tickets.data);
}
console.log('all tickets', allTickets);
}, [tickets.data]);
React.useEffect(() => {
if (tickets.data) {
setTickets(tickets.data);
}
console.log('all tickets', allTickets);
}, [tickets.data]);
13 Replies
Neto
Netoβ€’2y ago
const { data } = trpc.company.userCompany.useQuery(undefined, {
onSuccess: (data) => {
const { data } = trpc.company.userCompany.useQuery(undefined, {
onSuccess: (data) => {
you can switch the undefined by the query props
Son
Sonβ€’2y ago
thank you so much!!! ive been stuck on this for hours. where is information like this in the docs?
Neto
Netoβ€’2y ago
trpc client works on top of react query
Son
Sonβ€’2y ago
i'm not that familiar with react query, thats my problem. thank you again, i got work to do. πŸ™πŸΎ πŸ™πŸΎ πŸ™πŸΎ
Neto
Netoβ€’2y ago
gl
Son
Sonβ€’2y ago
one more question. why do we have the undefined as a first param
Neto
Netoβ€’2y ago
the first param is the query input and you if use null it warns you Argument of type 'null' is not assignable to parameter of type 'void | undefined'.ts(2345)
Son
Sonβ€’2y ago
since we cant use devtools, thats why we pass undefined?
Neto
Netoβ€’2y ago
you pass undefined because the query doesnt need any input specifically why its undefined idk and you can use devtools
Neto
Netoβ€’2y ago
Devtools | TanStack Query Docs
Wave your hands in the air and shout hooray because React Query comes with dedicated devtools! Γ°ΕΈΒ₯Β³ When you begin your React Query journey, you'll want these devtools by your side. They help visualize all of the inner workings of React Query and will likely save you hours of debugging if you find yourself in a pinch!
Neto
Netoβ€’2y ago
GitHub
jobs/_app.tsx at main Β· STNeto1/jobs
Contribute to STNeto1/jobs development by creating an account on GitHub.
Son
Sonβ€’2y ago
okay i got read up on react query, thanks for the resources.
Neto
Netoβ€’2y ago
reactquery
Want results from more Discord servers?
Add your server