FluX
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