-
Hi! Is there any way to implement queries invalidation from queries definition itself? const booking = useMutation({
queryKey: ['booking'],
onSuccess: () {
queryClient.invalidateQuery(['userStat'])
queryClient.invalidateQuery(['dashboard'])
}
})
const userStat = useQuery({
queryKey: ['userStat'],
})
const dashboard = useQuery({
queryKey: ['dashboard'],
}) But I want booking mutation to be simple and don't know about other queries. Something like this: const booking = useMutation({
queryKey: ['booking'],
})
const userStat = useQuery({
queryKey: ['userStat'],
invalidateOnQueryKey: ['booking'],
})
const dashboard = useQuery({
queryKey: ['dashboard'],
invalidateOnQueryKey: ['booking'],
}) |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Dec 8, 2024
Replies: 1 comment 1 reply
-
that’s pretty much why we have queryKeys:
then, you can invalidate everything
not sure if “booking” and “stats” are correctly grouped into “user” but I hope it gets the concept accross. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Kein1945
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that’s pretty much why we have queryKeys:
then, you can invalidate everything
user
related with:not sure if “booking” and “stats” are correctly grouped into “user” but I hope it gets the concept accross.