trpc icon indicating copy to clipboard operation
trpc copied to clipboard

feat: conditional useQuery args

Open niikeec opened this issue 3 years ago โ€ข 1 comments

Describe the feature you'd like to request

Make the args in useQuery conditional that way input doesn't have to be passed if it's not required.

Currently, if a procedure doesn't include an input and you want to access the options arg in useQuery you still have to pass an input value of undefined.

const result = trpc.router.greeting.useQuery(undefined, {
    onSuccess: (data) => console.log(data)
});

Describe the solution you'd like to see

If there's no input, make options accessible without the need to pass an input.

const result = trpc.router.greeting.useQuery({
    onSuccess: (data) => console.log(data),
});

Describe alternate solutions

N/A

Additional information

No response

๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing

  • [X] ๐Ÿ™‹โ€โ™‚๏ธ Yes, I'd be down to file a PR implementing this feature!

niikeec avatar Feb 06 '23 17:02 niikeec

If it can be done in a non-hacky way, be my guest, but I'm doubtful we'll find a nice solution

KATT avatar Feb 10 '23 10:02 KATT

It feels like this might become possible with Tanstack Query v5 - they are deprecating overloaded functions and moving to object syntax as the default. This should enable something like trpc.someProcedure.useQuery({ input?, opts })

c-ehrlich avatar Feb 26 '23 21:02 c-ehrlich

This should enable something like trpc.someProcedure.useQuery({ input?, opts })

We actually had that API for a while during v10 alpha/beta but got feedback that it got unclear what is trpc options and what is RQ options

KATT avatar Feb 26 '23 21:02 KATT

If it can be done in a non-hacky way, be my guest, but I'm doubtful we'll find a nice solution

You're right. I'll close this.

niikeec avatar Mar 01 '23 22:03 niikeec