Why useMutation
is designed as not able to share status and data between multiple component?
#6118
-
I am new to React Query and trying to use it to server state management. I have a login business process that can be simplified like below:
Personal thoughtsIt is obvious that both ConfusionThe trouble here is becaz
So the custom
Questions
It is grateful in advance for reading this long text. It would be much appreciated if anyone could try to answer it. :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Because every time you invoke a mutation by calling
Usually, you use a mutation to make a change on the server, then you have a query to request the resource that was changed by the mutation to share data for that resource. So whatever your if that's not possible, we have a new hook useMutationState in v5 that can give you access to all mutations for a mutationKey, for example:
note that |
Beta Was this translation helpful? Give feedback.
Because every time you invoke a mutation by calling
mutate
ormutateAsync
, you create a new mutation. So if you mutate twice, there will be two mutations for the same key. That's a fundamental difference to queries, where there can only ever be one entry for a key, and multiple calls to the queryFn will be deduplicated. There is no deduplication for mutations. If you domutate('foo')
andmutate('bar')
, it will be two requests, and two mutations in the MutationCache.Usually, you use a mutation to make a change on the server, then you have a query to request …