Enable both `useQuery` and a raw `query` from the frontend (for use in async validation)
Hello everyone, some context:
Question: In
mockDbEmailCheck
, I'd like to be able to run a raw query against trpc: something like const emailIsUnique = await trpc.xxx.emailIsUnique.query({email})
. Is there a way to execute raw trpc queries from the frontend, as well as maintain the useQuery
tanstack query wrapper?
Essentially is it possible to create this:
Thanks everyone!3 Replies
How come you're using a query for sending data? It's best to use a mutation, and then react-query does give you an imperative API you can use
Ah I'm not, I'm using a mutation in the form submit. Thats just a oversight in the example code. I'm trying to use the query in the zod schema, where I need it to be an imperative call
Yes if you need an imperative call, use a mutation
In general Queries are for getting data with simple parameters, mutations are for sending data. A validation procedure is more of a mutation