-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
Describe the bug
<script setup lang="ts">
import { reactive } from 'vue';
import { useQuery } from '@tanstack/vue-query';
const obj = reactive<{ foo?: string }>({});
const query = useQuery({
queryKey: ['demo', () => obj.foo],
// queryKey: ['demo', () => obj.foo, obj.foo], <== no error, but redundant
queryFn: () => fetch(`/mock/getSomething/${obj.foo}`),
enable: () => !!obj.foo,
});
</script>For codes like above, @tanstack/query/exhaustive-deps rule will throw an error:
The following dependencies are missing in your queryKey: obj.fooYour minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-ucguwp?file=src%2FApp.vue
Steps to reproduce
pnpm run lint- see the error
Expected behavior
Is it possible to see getter as a dep in queryKey, or we can only wrap it in computed to escape this error?
<script setup lang="ts">
import { reactive } from 'vue';
import { useQuery } from '@tanstack/vue-query';
const obj = reactive<{ foo?: string }>({});
const foo = computed(() => obj.foo);
const query = useQuery({
queryKey: ['demo', foo],
queryFn: () => fetch(`/mock/getSomething/${foo.value}`),
enable: () => !!foo.value,
});
</script>How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Not related
Tanstack Query adapter
None
TanStack Query version
v5.57.1
TypeScript version
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels