T
TanStack•15mo ago
flat-fuchsia

can you break down `cancelQueries` to me?

I did not understand this part. I am using optimistic updates but there are no fetches being made during the onMutate callback call while using useMutation. I do not understand what is supposed to happen if I do not use cancelQueries in onMutate like the docs suggest 🤔
No description
1 Reply
like-gold
like-gold•15mo ago
Hi there, it's simple. Let's say you have a query [todos] And you are trying to create a new todo, then update the [todos]. If during the mutate call your [todos] query will be triggered for some reason you will have the race condition between mutate and [todos]. It may happen that [todos] will come after mutate.onSuccess and it will rewrite the [todos] with old data, that doesn't include your new todo. That is why you need to cancel outgoing [todos] call if there's any, to prevent this.

Did you find this page helpful?