Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useIsFetching is reacting only to first static queryKey #7680

Open
sadeghbarati opened this issue Jul 6, 2024 · 0 comments
Open

useIsFetching is reacting only to first static queryKey #7680

sadeghbarati opened this issue Jul 6, 2024 · 0 comments

Comments

@sadeghbarati
Copy link

sadeghbarati commented Jul 6, 2024

Describe the bug

export function useCaptchaQuery(queryKey: string) {
	const data = useQuery<{
		userId: string
		id: string
		title: string
		completed: boolean
	}>({
		refetchOnMount: true,
		retry: true,
		retryOnMount: false,
		queryKey: ['auth', 'captcha', queryKey],
		async queryFn() {
			return $fetch('https://jsonplaceholder.typicode.com/todos/1')
		},
	})

	return data
}

For example this query contains two static queryKey like auth and captcha and one dynamic queryKey
I want to check if tanstack query is fetching this API with useIsFetching hook but

  • useIsFetching({ queryKey: ['auth'] }) ✅
  • useIsFetching({ queryKey: ['captcha'] }) ❌
  • useIsFetching({ queryKey: ['auth', 'captcha'] }) ❌
  • useIsFetching({ queryKey: ['auth', 'dynamicQueryKey'] }) ❌

useIsFetching is only works with first static query key

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-uii3jr

Steps to reproduce

  1. Go to Stackblitz demo check hooks/useCaptcha.ts
  2. Then go to Captcha.tsx component which is using useCaptchaQuery query hook
  3. In the App.tsx, I added three buttons to check useIsFetching hooks with different queryKeys but only auth queryKey is working and it will disable the last button on the load and refetch event

Expected behavior

Those three buttons in Stackblitz playground should be disabled on the first load and the refetch event

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: [Windows 11]
  • Browser: [Chrome]
  • Version: [126.0.6478.127 64bit]

Tanstack Query adapter

react-query

TanStack Query version

v5.50.1

TypeScript version

v5.5.3

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant