FluX
Explore posts from serversInfer TRoot and TProcedure for specific procedures (polymorphism)
Hello!
I'm trying to build a custom hook that returns specific procedures of a router:
How can I infer TRoot and TProcedure? Currently it is typed as
any
in T extends RequiredProcedures<any, any>
. But of course now my input and output types are also any
, which I don't want.
Any help is appreciated! :) Thanks!2 replies
Possible to build this custom hook?
Hello! I'm facing a challenge and hope to get some guidance here.
I'm building an admin dashboard for creating and editing data - let's just say it's product data.
I built a product management form that I want to use for both creating and editing a product, because the fields are the same.
I'd like to build a custom hook which returns multiple
useQuery
s or useMutation
s for a tRPC route. The hook might look like this:
I've tried creating such a hook but it's not very great and absolutely not type-safe.
Any idea how this could be properly implemented? Would appreciate any help :)
4 replies
TTCTheo's Typesafe Cult
•Created by FluX on 3/8/2023 in #questions
Question about Planetscale storage utilization
1 replies
TTCTheo's Typesafe Cult
•Created by FluX on 2/12/2023 in #questions
Forms: How would you go about updating relations from the frontend?
(long-ish post)
I'm currently building an admin dashboard, where you can manage users for example.
A user can be edited by going to
/dashboard/users/<userid>
, and there I fetch the whole user object including relations (role object, permissions object).
I'm using Formik to handle my user editing form and I'm a bit uncertain about how to tackle updating all of the relations - especially the permissions. I want these to be toggleable via checkboxes.
One way of doing this is to take the initial permissions object with all its nested permissions and create a copy of it (Formik does this for you). Then I can remove individual permissions from that object, or add a permissions unique name to it. Finally, I can compare that to the initial values and see which permissions got removed or which got added, and do multiple DB queries based on that (connect/disconnect user from permission). Maybe create endpoints like /addUserPermission
and /removeUserPermission
?
Is this a good approach? Or is there maybe a better way that requires fewer queries?2 replies