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
useQuery
s or
useMutation
useMutation
s for a tRPC route. The hook might look like this:
// single query/mutationconst mutation = useApi((router) => router.admin.product.edit)const query = useApi((router) => router.public.product.details)// or multiple hooks for a routerconst { editMutation, createMutation } = useApi((router) => router.admin.product)// ^// | with type error, if tRPC route (e.g. `admin.product.edit`) does not exist
// single query/mutationconst mutation = useApi((router) => router.admin.product.edit)const query = useApi((router) => router.public.product.details)// or multiple hooks for a routerconst { editMutation, createMutation } = useApi((router) => router.admin.product)// ^// | with type error, if tRPC route (e.g. `admin.product.edit`) does not exist
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 :)
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...