Replies: 2 comments
-
I am also working on a chat/messaging app, and have this exact same issue , where calling mutate on a Mutation instance/entry from the variables state just duplicates the mutation instead of handling the original one. Due to this I gave up on relying directly on the cached variables state, and had to create a workaround by having a separate failedMessages state, and then updating it manually with onError and onMutate. inside useMutation..
And then I just display the failedMessages on the UI and it worked fine. |
Beta Was this translation helpful? Give feedback.
-
@anatolzak I'm facing a similar issue and would love to know if you eventually found a solution to that problem? |
Beta Was this translation helpful? Give feedback.
-
I am trying to implement a UI that supports issuing multiple mutations with optimistic UI AND allowing the user to retry a failed mutation.
Imagine, I have a chat app, where the user should be able to:
I currently don't see a way to do that while allowing multiple mutations at the same time.
I see that the Optimistic Updates UI example shows pending state using
variables
and retrying a failed mutation usingisError
,mutate
, andvariables
. However, this seems to only work if only allowing 1 mutation at a time.I have already figured out how to show pending state of multiple mutations using
useMutationState
and filtering for pending mutations and selecting the variables for each mutation. This returns an array of the pending mutations.However, I haven't been able to figure out how to show multiple failed mutations and allow the user to retry them. If I use
useMutationState
and filter bypending
orerror
, now I will get an array of either pending or failed mutations. I can allow the user to retry the failed mutations by callingmutate
again for the failed variables, however react query is just going to add a new mutation instance instead of retrying the same instance. Meaning the failed messages showing in the UI will never get removed.I feel like what I am asking for is a realistic way of using mutations that many big apps would need, but unless I am wrong, I don't see a way to accomplish this easily.
I highly appreciate any feedback!
Beta Was this translation helpful? Give feedback.
All reactions