
discord-questions.trpc.io/m/1311807422939140147
Preview meta tags from the discord-questions.trpc.io website.
Linked Hostnames
5- 3 links todiscord-questions.trpc.io
- 1 link todiscord.com
- 1 link todiscord.gg
- 1 link togithub.com
- 1 link towww.answeroverflow.com
Thumbnail
Search Engine Appearance
Possible to build this custom hook? - tRPC
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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
Bing
Possible to build this custom hook? - tRPC
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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
DuckDuckGo

Possible to build this custom hook? - tRPC
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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
General Meta Tags
6- titlePossible to build this custom hook? - tRPC
- charsetutf-8
- viewportwidth=device-width, initial-scale=1
- next-size-adjust
- descriptionHello! 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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
Open Graph Meta Tags
3- og:titlePossible to build this custom hook? - tRPC
- og:descriptionHello! 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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
- og:imagehttps://discord-questions.trpc.io/og/post?id=1311807422939140147
Twitter Meta Tags
4- twitter:cardsummary_large_image
- twitter:titlePossible to build this custom hook? - tRPC
- twitter:descriptionHello! 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: ```ts // single query/mutation const mutation = useApi((router) => router.admin.product.edit) const query = useApi((router) => router.public.product.details) // or multiple hooks for a router const { 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 :) ```ts export const useManager = <FormData extends FieldValues>( router: keyof AppRouter["admin"], dataMode: "create" | "edit" ) => { const nextRouter = useRouter() function getMutation(): UseTRPCMutationResult<FormData, any, any, any> { if (dataMode === "create") { // @ts-ignore return trpc.admin[router].create.useMutation() } else { // @ts-ignore return trpc.admin[router].edit.useMutation() } } const mutation = getMutation() async function submit(data: FormData) { return await mutation.mutateAsync(data) as FormData } // @ts-ignore const deleteMutation: UseTRPCMutationResult<FormData, any, any, any> = trpc.admin[router].delete.useMutation() async function purge(slug: string) { return await deleteMutation.mutateAsync({ slug }) } const isLoading = mutation.isPending || deleteMutation.isPending return { submit, isLoading, redirect: nextRouter.push, purge } } ```
- twitter:imagehttps://discord-questions.trpc.io/og/post?id=1311807422939140147
Link Tags
8- canonicalhttps://discord-questions.trpc.io/m/1311807422939140147
- iconhttps://cdn.answeroverflow.com/867764511159091230/6af104c7f0f39a12fcd55bd7bd28928f/icon.png
- preloadhttps://www.answeroverflow.com/_next/static/media/4f05ba3a6752a328-s.p.woff2
- preloadhttps://www.answeroverflow.com/_next/static/media/9cf9c6e84ed13b5e-s.p.woff2
- preload/discord/2.png
Links
7- https://discord-questions.trpc.io
- https://discord-questions.trpc.io/search
- https://discord-questions.trpc.io/u/269563551012749313
- https://discord.com/channels/867764511159091230/1311807422939140147/1311807422939140147
- https://discord.gg/bvFvwRGW74