tRPCttRPC
Powered by
PeformP
tRPC•2y ago•
2 replies
Peform

conditionally fetching data with a useQuery

Hello,

From my understanding a
useMutation
useMutation
is primarily for updating/deleting/creating a record. And a
useQuery
useQuery
is primarily used for fetching data from the server. However, when it comes to conditionally fetching data from the server I belive the syntax for a
useMutation
useMutation
is much more ideal?

I'm not sure if I am missing something, or if in this scenario it would be better to use a
useMutation
useMutation
.

The issue is, I only want to query the API when the user presses a specific button and once they have input a userId to search. I also want to display a toast (notification) when the request has finished. However, the
onSuccess
onSuccess
and
onError
onError
callbacks are depreciated, meaning I have to now use a
useEffect
useEffect
. This is greatly overcomplicating everything. I'm not sure if there is a better way of doing this? Any advice would be appreciated.
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

useQuery caching data
НиткаННитка / ❓-help
2y ago
useQuery returning old data with new params
uzelacUuzelac / ❓-help
3y ago
useQuery always fetching when active on page
halfmoonHhalfmoon / ❓-help
3y ago