Skip to content

Inversion of control for invalidate query #8416

Answered by TkDodo
Kein1945 asked this question in Q&A
Discussion options

You must be logged in to vote

that’s pretty much why we have queryKeys:

const userStat = useQuery({
  queryKey: ['user', 'stat'],
})
const dashboard = useQuery({
  queryKey: ['user', 'dashboard'],
})

then, you can invalidate everything user related with:

const booking = useMutation({
  onSuccess: () {
     queryClient.invalidateQuery(['user'])
  }
})

not sure if “booking” and “stats” are correctly grouped into “user” but I hope it gets the concept accross.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Kein1945
Comment options

Answer selected by Kein1945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants