Invalidate Query not triggering a refetch #8446
Unanswered
rampantslug
asked this question in
Q&A
Replies: 1 comment
-
I can't be certain it'll fix the problem, but I notice that you are returning From the docs there's no need to Here's the example code import { useMutation, useQueryClient } from '@tanstack/react-query'
const queryClient = useQueryClient()
// When this mutation succeeds, invalidate any queries with the `todos` or `reminders` query key
const mutation = useMutation({
mutationFn: addTodo,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['todos'] })
queryClient.invalidateQueries({ queryKey: ['reminders'] })
},
}) |
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
-
I have a couple of other RN apps that use invalidateQueries successfully and despite copying that code verbatim into my current project it doesnt seem to trigger the refetch on the same screen (I have to navigate away and then back again to see the change).
I even dropped Query version to match the other project that was working fine.
Here are my query and mutation hooks
Here is a simple screen that I am using them in
If I test using my temp button there it WILL update the backend data and call the onSuccess in the mutation but the query wont fire again until I navigate away from the page and then back again.
I was previously doing the update in another page and then routing back to this one and it wouldnt update at all. But putting both the mutation and the query in this page to simplify it and closing can get the update to happen if I close and then reopen this screen.
Any thoughts, or obvious things that I might be doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions