Help with setQueryData #6850
Unanswered
Ttislevoll
asked this question in
Q&A
Replies: 1 comment
-
making a mutation doesn't automatically update a query - you need to either invalidate or update directly. I don't know why it doesn't work because I don't really understand that code. Please show a codesandbox reproduction with your issue. |
Beta Was this translation helpful? Give feedback.
0 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!
I have some troubles with mutations. I have a code that loops trough a ordersQuery and run mutations on affected orders.
First, it finds the specified order to mutate:
Then, it loops trough the orderQuery again, finds a list of affected orders and mutates these orders:
Finally, i loop trough the orders again, to ADD some weight
The issue is that when I get to mutation to ADD the property weight, the order from ordersQuery will have the un-mutated old values, making the logic for calculating newWeight not work correctly, and updating it with wrong values
I need to update the entire orderQuery immediately after the first remove mutation.
I have tried using
queryClient.invalidateQueries({ queryKey: ['Orders'] })
right after the remove-mutation, but it doesnt seem to affect it.I've also tried the
setQueriesData
like this:But that doesn't seem to do anything.
What am I missing here?
Edit: Formatting
Beta Was this translation helpful? Give feedback.
All reactions