FluX
Wrong type for results
Afaik you need to use a transformer
https://trpc.io/docs/server/data-transformers
5 replies
Type error when following guide TRPC React query: 'lazy' is declared here.
Make sure your server and client are using the exact same version of trpc. That should usually fix errors like this one. (If your versions are already in sync, I unfortunately have no clue what's wrong)
4 replies
File based structuring, trpc layout
That's not possible as far as I'm aware. You always need to define the structure of your router in code.
One approach that comes close to what you're asking is to create nested routers and organize routers and procedures like so:
You'll still need to add your procedures to your routers in code
3 replies
I'm trying to get type for queries/mutations returned from trpc use hooks, but they are different
This is how I did it:
And here is the same for the new
tanstack-react-query
integration:
You should be able to build types for useMutation
the same way. I have no examples for that7 replies
Where did useUtils go?
useUtils
is just a wrapper around Tanstack Query. See https://trpc.io/docs/client/react/useUtils#helpers
The new integration uses native Tanstack Query, removing the wrappers. For your case (the fetch call) I believe you must change your code to:
8 replies
correct way to handle errors run time errors
You could try the approach I posted here a few days ago:
https://discord.com/channels/867764511159091230/1337500157398355968/1337508102316232754
7 replies
Can't build NextJS with TRPC vanilla client.
I've had similar issues before and it has to do with path aliases in the tsconfig.
I think what's happening is that nextjs tries to resolve
@/collections
inside of the client
app folder and not inside the server
folder.
Unfortunately I don't have a solution for you, since I work around that by avoiding aliases in my trpc routers, though I agree using path aliases is way cleaner for imports.4 replies
error handling
I guess what you're referring to is the little error popup in Next.js.
What I like to do is to wrap my mutation call in a try/catch wrapper function and show a toast in case of errors.
Not sure if this is the best solution but it works.
9 replies
How to reset the cache without triggering refetches for none active queries ?
A quick search brings up this:
https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientclear
4 replies
What is the substitution for queryKey in useQuery?
If you have a
useQuery
hook like const hook = trpc.getUsers.useQuery({ username })
, where username
is a state that's tied to a search input, the query will re-run automatically when username
changes. No dependency array needed3 replies
How do *you* structure the tRPC router when dealing with isolated components?
In my apps I like to follow this structure: I have two top-level routers - an
adminRouter
and a publicRouter
.
The adminRouter
has many nested routers, e.g. userRouter
or productRouter
, where each nested router contains CRUD procedures for database entities.
Like you, I also have some one-off procedures I need to call in an admin dashboard. For example for clearing caches or for streaming OpenAI response data into an input field.
For that I decided to create a systemRouter
nested under adminRouter
, with routes like /trpc/admin.system.clearCaches
or /trpc/admin.system.openaiTranslation
.
If I'm guessing correctly and you're building a component to display comments of a post, maybe you already have like a commentsRouter
or postsRouter
where you can put that procedure. Otherwise think of a way to group this (and potential future one-off procedures) into a router.5 replies