How to use TRPC query without hooks

Hi guys! I'm new to TRPC so I see how you can fetch stuff in the backend with trpc using hooks like so const { data: videos } = api.videos.fetchVideos.useQuery(); but in my case I want to fetch once an action happens and pass in an argument that I get once user submits something. What is the best way to go about this?
Solution:
useMutation() | tRPC
The hooks provided by @trpc/react-query are a thin wrapper around @tanstack/react-query. For in-depth information about options and usage patterns, refer to their docs on mutations.
Jump to solution
7 Replies
chrollo
chrollo7mo ago
not sure if this is best way, but you can set enable to false in the query props, and destruct refetch, and call refetch whenever you want
dan
dan7mo ago
use a mutation. If the fetch is triggered by some other action, i.e user input, you want to use a mutation.
Solution
dan
dan7mo ago
useMutation() | tRPC
The hooks provided by @trpc/react-query are a thin wrapper around @tanstack/react-query. For in-depth information about options and usage patterns, refer to their docs on mutations.
rikisann
rikisann7mo ago
gotcha so the usemutation shouldn't be used for post type requests? Just for any request where you need to attach arguments once an event happens?
Josh
Josh7mo ago
More less yeah Think about the difference being "do I want to automatically call x, or manually call x" for choosing query vs mutation respectively
dan
dan7mo ago
^ this is bascially my logic behind selecting what one to use
rikisann
rikisann7mo ago
mmm gotcha interesanchi I appreciate you fellas
Want results from more Discord servers?
Add your server
More Posts