MrManafon
MrManafon
TTCTheo's Typesafe Cult
Created by MrManafon on 2/18/2024 in #questions
server actions & trpc
Here is one - its quite hard to organize server actions. You can't really group them into router namespaces like you do with our trpc - instead, each function has to be a function, and you then resort to naming patterns like Products_getById() to avoid conflicts
4 replies
TTCTheo's Typesafe Cult
Created by MrManafon on 2/18/2024 in #questions
server actions & trpc
Also wanted to give an example of using react query with server actions, before anyone says it is not possible:
const { data } = useQuery({
queryKey: ["posts"],
queryFn: () => myServerAction("post-id"),
});
const { data } = useQuery({
queryKey: ["posts"],
queryFn: () => myServerAction("post-id"),
});
4 replies
TTCTheo's Typesafe Cult
Created by MrManafon on 2/18/2024 in #questions
server actions & trpc
To give more context to the above, I've compiled a list of commonly stated reasons for one or the other, and why those reasons are invalid in this discussion: ☑️ You must have a Data Access Layer - yes, but you can have it with either trpc or server actions, it doesn't really change much. ☑️ trpc gives you better dx - Not significantly better. You get some very nice things, like formatting errors, but on the other hand, the procedure declaration is uglier and more confusing. You win some, lose some. ☑️ trpc gives you better type safety - I'm not entirely sure what that even means. Zod ensures type safety, and linter helps. Both of these work exactly the same with server components. ☑️ you get react query integration in trpc - tanstack query works exactly the same with server components. ☑️ server actions are unstabile - they've been stabile for a while now. ☑️ it's no extra work for you because Create T3 App takes care of all of the initial setup - sure, but the whole point of this conversation is to resolve this point. ❓ trpc has zod built-in - deciding what you use for runtime validation and sanitization is up to you and your controllers, not to trpc, t3 just made a decision to enforce it afaik, and we could do the same with server actions. So, no real difference between the two in any of those points. Lets focus on more tangible differences surrounding the deployment model and security.
4 replies