Why cannot I specify a mutation input with useQueryKey?

It's supported with queries, but for some reason not with mutations. Why is this the case?
S
snöw315d ago
The use-case is that I want global loading states for mutation with https://tanstack.com/query/v4/docs/react/reference/useIsMutating
useIsMutating | TanStack Query Docs
useIsMutating is an optional hook that returns the number of mutations that your application is fetching (useful for app-wide loading indicators). `tsx
S
snöw315d ago
which I need a key for, hence the need for useQueryKey
N
Nick315d ago
Mutations don’t typically have query keys, they’re not cached This is a react-query thing (I guess you get that though from the second link) Do we not expose isMutating via trpc.useContext? Many things that need query keys we do expose this way If not it might be because trpc.useMutation actually serves the same purpose in the context of trpc
S
snöw315d ago
useContext only gives you the queries, so no luck there
S
snöw315d ago
but I ended up here
S
snöw315d ago
useIsMutating with the predicate where I can access the variables works, but no typesaftey 😦 I guess this could be wrapped to a custom TRPC wrapper of useIsMutating where the type is narrowed based on the mutationKey
N
Nick315d ago
Yeah very possibly could be something we’ve missed Feel free to open a GitHub issue
S
snöw315d ago
I used useIsMutating straight from react-query, so nothing missed 😄 but yep, this can be a feature request
J
julius315d ago
iirc we have these in v11 Oh wait you wanna get the mutation key with input Nah
S
snöw315d ago
that was the initial idea, but a custom useIsMutating with the mutation state typed in the predicate would be a better solution
S
snöw315d ago
react-query hard sets the Mutation types to any, so a change would be required there as well
S
snöw315d ago
I had something like this in mind:
S
snöw315d ago
but the as step done by trpc anything specific I could check out?
R
Riccardo190d ago
Hey, I need somthing you solved with useIsMutating but with isMutating client helper. I filed an issue https://github.com/trpc/trpc/issues/4889, do you mind bringing some more ideas/support there?
More Posts
how to connect trpc server (t3 stack) from my external nextjs app?how to connect trpc server (t3 stack) from my external nextjs app?trpc.legacyRouterName.procedure "does not exist" on type CreateTRPCNextBase, runs anywayHave reached the end of a massive trpc 9 -> trpc 10 migration, executed using the official guide witNot getting legacy router ops in merged tRPC 9 routerFollowed the guide to merge my large tRPC 9 router with tRPC 10, but now I can't use useQuery or acccreateTRPCNext Type Error + useQuery Not DefinedI'm trying to use the conventions for `createTRPCNext ` from https://github.com/trpc/examples-next-pRead response headers on the clientIve been searching for a while trying to figure out how to access response headers on the client. FoIs it possible to access context in input?Hi, I have a validator that requires to get context of prisma in the `input`, Is it possible to get TRPCContextState not found in v10In our v9 app, we used TRPCContextState from internals to type out TRPC utils, importing it like `imRateLimiter for fastify tRPC routesHi, I would like to add Ratelimiter to a specific fastify trpc route, are there any solutions availaSubscriptionsare we able to send data over with subscriptions, to allow for full duplex communication ?Query tRPC the right wayIf you use graphql, you can precisely query what you exactly need and avoid over fetching, so you caHow does trpc subscription actively close/disconnect in the server?How do I actively disconnect my subscription?child router questionlet's say we have a monorepo, one server, two client apps (cat and dog). we make one appRouter, likHow to force SSL on projects using tRPC?Hello everyone, I'm working on a project that uses create-t3-app as boilerplate. My project is hosAWS Lambda / How to set Cookies inside ProceduresHow can I set and remove cookies similar to ctx.res.cookie(..) with Express when using the aws lambdMassive Type Errors on tRPC 10 Legacy Router against MergeRouterWe're trying to upgrade to tRPC 10 but I am running into a massive type clash when trying to merge rIs it possible to create 2 routers inside a single file?I am having an issue in which it is impossible to me to use a class instance within 2 routers. I triUse onError to change an application error into a TRPCError?I want to use the onError handler to change any instance of a custom application error into a TRPCErIncreasing Body 1mb limitHey, Im trying to build an application that allows sending of base64 encoded files to my next.js serNitro and tRPC in vercel-edgeHey there! I hope this is the right place to ask for help. I am trying to deploy an application witHow to retrieve and receive Bigint data to/from TRPC procedureNode: `v16.15.1` I'm trying to return an object which contains an `amount` property from one of my