trpc with nextjs 15
Does it makes sense using trpc with nextjs 15? Because there is server actions too but that's not type safe.
9 Replies
Server actions are type-safe though, can you explain why you think otherwise?
I’m also curious if there’s a reason to still use trpc in nextjs15
Even in the pages router
So trpc doesn’t makes sense in app router?
Honestly, if someone is a bit skeptical about all these new fancy Next.js-related features, it's better to use
And trust me, the end-to-end type safety that tRPC provides is beneficial any day. Server Actions are type-safe, but are they as simple to set up (For End-To-End Typesafety) and use as
Plus, Server Actions are meant for mutations, not for fetching—they only support
tRPC
. Prefetching on the server and using the server cache on the client is a really nice pattern. You kind of get the best of both worlds with that approach. Since tRPC integrates with TanStack Query, using it is also really simple.And trust me, the end-to-end type safety that tRPC provides is beneficial any day. Server Actions are type-safe, but are they as simple to set up (For End-To-End Typesafety) and use as
tRPC
? I don’t know.Plus, Server Actions are meant for mutations, not for fetching—they only support
POST
requests, not GET
. Even the React team doesn’t recommend using them for fetching purposes.
Prefetching on Server & use Cache on Client: Alex Sidorenko Tweet on this topic using SWRI’ve worked quiet a lot with server actions and I like them much more than trpc because of their simplicity in DX.
With serverrendering I had so far very rarely the case that I had to fetch client side - I think this remark is reasonable. I’d probably go with trpc just for fetch, if this would be needed.
It really depends on you. Other people might still prefer tRPC over server actions. I can't provide much value here since I'm no expert, but if you want simplicity, go for server actions.
Understood all the things u said, so for a large scale ecommerce app trpc will do the work better? Right?
Yeah, for any large scale app, its better to have some amount of separation between frontend & backend. So, for a large scale ecommerce, I would prefer to keep my
tRPC
completely separated, a standalone backend with either express or fastify with a monorepo.
Plus keeping your tRPC
seperate as backend, it would be easier to use that, If we decide to have mobile/desktop-client/app, using react native/electron.I got it thanks u so much