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
You can set the query to be {enabled: false} and refetch it inside useEffect.
Thank you
Will that also work for mutations ?
mutations dont run automatically so the problem is non existent
useMutation returns a mutate() function. You can run it from anywhere including hooks
I use mutateAsync
🤷 i dont see a big difference, you can just catch it now and show an event specific error
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
You can add onError function in the options inside useMutation
So can i catch it on the backend?
This kind of error
I don't want trpcClient errors tp spillover to the user
Something like .catch for await/async stuff
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
So are you saying i should use if block instead of useEffect?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Link to the blog post please
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View