-
I am trying to invalidate and refetch a query after performing a mutation on it by calling it in the method that the onSuccess option provides like so, const queryClient = useQueryClient();
return useMutation(updatedPlayerData => savePlayerProgressData(updatedPlayerData), {
onSuccess: savedPlayerData => {
queryClient.invalidateQueries(['playerData', 19]);
}
}); However, the associated data is not being updated on the screen and when I inspect the query in the Query Dev Tools, I can see the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
the code that you've posted looks fine. not having the correct query key would've been my first instinct. be aware of the types. maybe the number 19 should in fact be the string 19? (just guessing here). Otherwise, if you put it in a codesandbox example, I'm happy to take a look. But as you can see in the existing examples, invalidation like that works (see e.g. here: https://react-query.tanstack.com/examples/optimistic-updates) |
Beta Was this translation helpful? Give feedback.
-
I'm having a similar experience. I'm invalidating my single-string-key query but it won't refetch. If I refetch manually with the react-query-devtools, then it will refetch and rerender. Unexpectedly, all of the queries are marked "stale", never "fresh". But I cannot get the |
Beta Was this translation helpful? Give feedback.
the code that you've posted looks fine. not having the correct query key would've been my first instinct. be aware of the types. maybe the number 19 should in fact be the string 19? (just guessing here). Otherwise, if you put it in a codesandbox example, I'm happy to take a look. But as you can see in the existing examples, invalidation like that works (see e.g. here: https://react-query.tanstack.com/examples/optimistic-updates)