.mutate() underlying implementation

Can .mutate() substitute a fetch('POST') I switched fetch() to .mutate and everything is working out. I just don't understand what mutate does under the hood, I don't want there to be side effects, I just want to do a POST request ONCE and get a response, that's it.
18 Replies
mrnicericee
mrnicericee•2y ago
look at your network tab whenever you submit a mutate() all mutations are post methods
amanuel
amanuel•2y ago
Ok, good to know
mrnicericee
mrnicericee•2y ago
also the path is not your usual url
amanuel
amanuel•2y ago
In this case why use mutate () over fetch, other than consistency?
mrnicericee
mrnicericee•2y ago
could be like basePath/api/trpc/users.create
amanuel
amanuel•2y ago
Are there any other side effects though? I read that they refetch on stale data or something?
mrnicericee
mrnicericee•2y ago
you could do things like this
amanuel
amanuel•2y ago
Oh, so unless explicitly told It will only make 1 request And that's it No other concern
mrnicericee
mrnicericee•2y ago
yeah and you get all the cool things that trpc offers like go to definition and also the return of that mutation
amanuel
amanuel•2y ago
Yeah that's why I'm using it It's Mwuaaaah Thank you so much I'm asking because I'm literally processing a payment for this So I want to be 10000% sure Otherwise I would have reverted to good ol fetch and just feel safe that way
mrnicericee
mrnicericee•2y ago
there's also a retry on it if you want to try the request again
amanuel
amanuel•2y ago
Yeah I know, those things I got I just didn't know if without any configuration It still had some underlying side effects And I guess it does not So thank you so much
mrnicericee
mrnicericee•2y ago
yeah just look at the network tab 🙂
amanuel
amanuel•2y ago
Yeah but sometimes there is refetch on interval Or window focus Or something else So it's not as easy to check
mrnicericee
mrnicericee•2y ago
Important Defaults | TanStack Query Docs
Out of the box, React Query is configured with aggressive but sane defaults. Sometimes these defaults can catch new users off guard or make learning/debugging difficult if they are unknown by the user. Keep them in mind as you continue to learn and use React Query: Query instances via useQuery or useInfiniteQuery by default consider cached dat...
Want results from more Discord servers?
Add your server