Looking for solution for mutate dependency and multiple promises in mutate #3402
Unanswered
TommySorensen
asked this question in
Q&A
Replies: 1 comment 8 replies
-
You could have a queue, where if the mutation isLoading, the item gets stored in the queue instead of calling mutate. In the onSuccess, you could check the queue and mutate the variables in the queue if there is are variables waiting to be mutated. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all.
I am currently building a reusable basket hook with React Query for the server state.
I have search the discussions and issues for examples of running a GET request before i want to call a POST request with
useMutation
, but haven't found any good examples of it.Let's say that i 2 endpoints, one for creating(GET) a basket and one for updating(POST) it. The goal is to wait with creating the basket before i'm actually are putting something in it. So when user clicks "add to basket" i could in the
useMutation
do a fetch call, await it and then run the POST with the basket id i just created. This will properly work fine for first time running the mutate. But let's say the user can click the "add to basket" button multiple times, that will cause a issue since when clicking second time, the basket is not created and the previous promise i still running. So the question is: Are there anything that can handle cases like this i React Query?I tried something like this:
User journey:
Click "add to basket" button twice and expect the basket to contain a basket with quantity of 2 with only 2 requests, one for create and one for updating.
Beta Was this translation helpful? Give feedback.
All reactions