.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
look at your network tab whenever you submit a
mutate()
all mutations are post
methodsOk, good to know
also the path is not your usual url
In this case why use mutate () over fetch, other than consistency?
could be like
basePath/api/trpc/users.create
Are there any other side effects though? I read that they refetch on stale data or something?
you could do things like this
Oh, so unless explicitly told
It will only make 1 request
And that's it
No other concern
yeah and you get all the cool things that trpc offers like
go to definition
and also the return of that mutationYeah 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
there's also a retry on it if you want to try the request again
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
yeah just look at the network tab 🙂
Yeah but sometimes there is refetch on interval
Or window focus
Or something else
So it's not as easy to check
this should help 🙂
https://tanstack.com/query/v4/docs/guides/important-defaults
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...
client side is just a wrapped tanstack query w/ some dope helpers
Yeah, this only affects useQuery though
Right?
mmhmm