useQuery Fetching twice?!
hi, i am new the tanstack query. this is my first time using, i followed the guide, however when call "onRefreshCaptcha" the network fetch is doing twice for "captcha_img"
`
const isImgLoading = ref(false)
const queryClient = useQueryClient()
const { data, isFetching, suspense } = useQuery({
queryKey: ['api/agent/v1/captcha_img'],
onSuccess: () => {
isImgLoading.value = true
console.log('api/agent/v1/captcha_img', data.value)
emit('success', data.value)
}
})
const onRefreshCaptcha = async () => {
queryClient.invalidateQueries({ queryKey: ['api/agent/v1/captcha_img'] })
}
await suspense()
return { data, onRefreshCaptcha, isFetching, isImgLoading }
~


2 Replies
absent-sapphire•3y ago
could be one fetch from window focus + one more from invalidation
continuing-cyanOP•3y ago
thanks. sorry for asking such a dumb question. i didn't read the "important defaults" properly . could i request from you a service (if interested , pls do let me know your charges) to help advise me how is the correct way to use tanstack vuequery base on my project code . i will only ask a few as some in doubt.. cud u PM me if interested ?