useMutation calls function twice when I don't have retry set up #1649
-
Hi all! I've been trying out react-query for the past few days and so far it looks great. However, I am seeing a weird issue when doing a mutation. I've been following the docs here and here.
postNewGoal is just an API call that sends an object. The issue I'm seeing is that the postNewGoal function is called twice. This works fine:
However, there is an issue with it on some occasions - the invalidateQueries call can get called before the post has finished. Meaning that for a brief period it looks as if the action was not completed and then when react-query re-fetches it's fine again. Any idea why that might be happening and how can I use the callback format? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Ha! I figured it out... I was being a dummy and finally understood that I should not have the API call in the onMutate callback. It was calling it once as the first parameter to useMutation and a second time because of the onMutate call. I had just misunderstood the docs :) Feel free to delete this discussion. |
Beta Was this translation helpful? Give feedback.
-
I ran into this today and my reason was because my mutation was in a useEffect under a strict mode react hierarchy. |
Beta Was this translation helpful? Give feedback.
Ha! I figured it out... I was being a dummy and finally understood that I should not have the API call in the onMutate callback. It was calling it once as the first parameter to useMutation and a second time because of the onMutate call. I had just misunderstood the docs :) Feel free to delete this discussion.