.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•3y ago
look at your network tab whenever you submit a mutate() all mutations are post methods
amanuel
amanuelOP•3y ago
Ok, good to know
mrnicericee
mrnicericee•3y ago
also the path is not your usual url
amanuel
amanuelOP•3y ago
In this case why use mutate () over fetch, other than consistency?
mrnicericee
mrnicericee•3y ago
could be like basePath/api/trpc/users.create
amanuel
amanuelOP•3y ago
Are there any other side effects though? I read that they refetch on stale data or something?
mrnicericee
mrnicericee•3y ago
you could do things like this
amanuel
amanuelOP•3y ago
Oh, so unless explicitly told It will only make 1 request And that's it No other concern
mrnicericee
mrnicericee•3y ago
yeah and you get all the cool things that trpc offers like go to definition and also the return of that mutation
amanuel
amanuelOP•3y 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•3y ago
there's also a retry on it if you want to try the request again
amanuel
amanuelOP•3y 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•3y ago
yeah just look at the network tab 🙂
amanuel
amanuelOP•3y 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•3y 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...
mrnicericee
mrnicericee•3y ago
client side is just a wrapped tanstack query w/ some dope helpers
amanuel
amanuelOP•3y ago
Yeah, this only affects useQuery though Right?
mrnicericee
mrnicericee•3y ago
mmhmm
Want results from more Discord servers?
Add your server