How to Pass (Dynamic) Variables in trpc.useQuery()?
I know I can do this:
const findSubscriber = trpc.useQuery(["subscriber.find", { email: "[email protected]" }]);
But what if I want the user to type in an email & then see if that email exists with subscriber.find
? So I want to execute my query conditionally, that is, only in an onClick
, as I don't have the user input before that.17 Replies
Enabled: false and use refetch prob
thanks a lot!!
And if you want to delay:
, {enabled: !!email}
as mentioned abovethanks, i'll try it out right now! 🙂
Is it correct that when I have
enabled: false
, there should not be an initial request to my trpc endpoint? Right now, when I reload, it will hit that endpoint every time initially.Other queries may have requested it, all the hooks are batched into one request
hmmm ... I only have this one component, as I am trying to learn trpc right now. When I remove the component, no request is made. The component itself is pretty basic:
sorry I don't want to annoy you guys too much here, just a bit confused right now
If anyone knows what I'm missing here, that would be appreciated! Otherwise thanks a lot already!!
This should be "disabled", it's possible trpc fires the query with an empty body as part of the batching process
But you should be confident that this won't touch your backend if the value passed to
enabled
is falsySorry, what should be
disabled
?The query you wrote
Ah ok, so you mean that this should work?
Yes that should be fine
hmm okay!
thanks a lot theo! 🙂
npnp!
Practical React Query
Let me share with you the experiences I have made lately with React Query. Fetching data in React has never been this delightful...
Highly recommend this series
thanks!!