Next.js API Type Safety without tRPC?
I'm having issues with tRPC and am thinking of removing it from my project.
Since I'm using App Router, it's less of a problem when calls are made on the server.
However, I still need to make calls from client side. What are some good solutions for that?
7 Replies
server actions
Yes, but I'm asking about the client side
you can call server actions from the client
Yes, but I'm talking about things other than Server Actions. They're not ideal for everything. That's why people still use tRPC with App Router.
You can try using Tanstack query. I have used it in a project and I wrap the layout with a Provider component. This does not interfere with my server actions and even lets me do client calls with all the tanstack query utilities.
You might want to explain the problems you're having with tRPC and what your needs are, otherwise it's difficult to recommend anything
It was this issue that's currently fixed, but I just prefer not having a dependency if I don't really need it. If I could achieve almost the same results without tRPC, then it's better to remove this layer and keep the setup simple to develop and to debug
TanStack libraries are awesome. Do you have some sample code or article that talks about this setup? Seems to me that the library works best either with tRPC or with external APIs. I haven't been able to find the "define a function and call it" experience anywhere else.