FluX
Explore posts from serversTTCTheo's Typesafe Cult
•Created by AmohPrince on 2/27/2025 in #questions
Where the hell do you guys buy your domains
I've been using Namecheap for a few years and been very happy with it. They have great filters for finding TLDs by topic. But in the end I'd say it's mostly personal preference
13 replies
TTCTheo's Typesafe Cult
•Created by plyglt on 2/25/2025 in #questions
How do I prefetch trpc serverside and then hydrate the client?
You are probably looking for this https://trpc.io/docs/client/react/server-components
4 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
TTCTheo's Typesafe Cult
•Created by MrMasolov on 2/15/2025 in #questions
Fetch data in Next app to be available across all app
More info here:
https://react.dev/learn/passing-data-deeply-with-context
https://react.dev/reference/react/createContext
3 replies
TTCTheo's Typesafe Cult
•Created by MrMasolov on 2/15/2025 in #questions
Fetch data in Next app to be available across all app
I would create a React context and place it in the root layout, wrapping the rest of your app.
E.g. if you need the current user information, create a UserProvider
... and then just place it in your root layout.
You can then use
const { user } = useUser()
in any client component.3 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