Next.js Discord

Discord Forum

Which to pick, server actions or trpc?

Unanswered
Cape May Warbler posted this in #help-forum
Open in Discord
Cape May WarblerOP
I wonder if one of these is superior in your opinion. Right now I'm during making of my engineering degree project and I wonder which to pick. I heard server actions are safer, don't require any set up and also provide type safety. TRPC on the other hand has great auth system and you can do lots of middlewares. What do you think?

4 Replies

Great golden digger wasp
If strong type safety and minimal setup are crucial and you have simpler CRUD operations, server actions might be more suitable. However, if you need advanced authentication features and extensive middleware capabilities, tRPC could be the better choice.
@Cape May Warbler I wonder if one of these is superior in your opinion. Right now I'm during making of my engineering degree project and I wonder which to pick. I heard server actions are safer, don't require any set up and also provide type safety. TRPC on the other hand has great auth system and you can do lots of middlewares. What do you think?
Use server components to read data then use server actions to mutate data. trpc won’t work there.

Use trpc useQuery to read data then use trpc useMutation to mutate data. Server actions won’t be better in this case.

So: depending on how you get the data, you should use the corresponding tool to mutate the data.
@Cape May Warbler Yeah but I can use useQuery with server actions, how they don't get better? They are equal or do I miss something?
Only use server actions for mutations. Don’t use them for querying. The reason is that server actions are queued and cannot be made to run in parallel.