pbesh
pbesh
TtRPC
Created by pbesh on 9/23/2022 in #❓-help
Recommended way to prefetch client-side
In react-query, you can do
queryClient.prefetchQuery(['todos', input], queryFn)
queryClient.prefetchQuery(['todos', input], queryFn)
In trpc, I seem to only have access to the useQuery option on my endpoints:
trpc.todos.useQuery(input)
trpc.todos.useQuery(input)
Is there a way to do trpc.todos.prefetchQuery(input) or similar?
4 replies
TtRPC
Created by pbesh on 9/23/2022 in #❓-help
Modifying payload client-side before caching
Say I have a payload that includes something like category_id in each of the items returned e.g.:
[
{ category_id: 1, ...},
{ category_id: 2, ... },
]
[
{ category_id: 1, ...},
{ category_id: 2, ... },
]
but I want to expand that client side to also include a full category: Category object, e.g:
[
{ category_id: 1, category: { ... } /* some Category object corresponding to id 1 */, ... },
{ category_id: 2, category: { ... } /* some Category object corresponding to id 2 */, ... },
]
[
{ category_id: 1, category: { ... } /* some Category object corresponding to id 1 */, ... },
{ category_id: 2, category: { ... } /* some Category object corresponding to id 2 */, ... },
]
I only want to do this once and have the expanded objects cached. When using react-query directly, you can do this by just doing it in your query function. Is there a way to do this with tRPC? Some kind of "transform before caching" option?
8 replies