how can i useQuery() useMutation() in a useEffect

I have a response sensitive trpc(t3 stack) route With the current way t3 stack works this is a bad idea Because everything must be block scope i can wrap calls in useEffect to enable me determine when it should be triggered So in a nutshell how can i triggered calls based on a events/ like when length of an input field is greater than 10 etc
16 Replies
Matvey
Matvey•2y ago
You can set the query to be {enabled: false} and refetch it inside useEffect.
Lopen
LopenOP•2y ago
Thank you Will that also work for mutations ?
barry
barry•2y ago
mutations dont run automatically so the problem is non existent
Matvey
Matvey•2y ago
useMutation returns a mutate() function. You can run it from anywhere including hooks
Lopen
LopenOP•2y ago
I use mutateAsync
barry
barry•2y ago
🤷 i dont see a big difference, you can just catch it now and show an event specific error
Lopen
LopenOP•2y ago
Also on last thing How to properly catch zod validation errors so it doesn't go to the front-end try catch block doesn't catch it
Matvey
Matvey•2y ago
You can add onError function in the options inside useMutation
Lopen
LopenOP•2y ago
So can i catch it on the backend?
Lopen
LopenOP•2y ago
This kind of error
Lopen
LopenOP•2y ago
I don't want trpcClient errors tp spillover to the user Something like .catch for await/async stuff
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Lopen
LopenOP•2y ago
So are you saying i should use if block instead of useEffect?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Lopen
LopenOP•2y ago
Link to the blog post please
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server