-
Describe the bugI have a question: has anyone else encountered a situation where eslint does not show the error mentioned in this link? https://tanstack.com/query/v5/docs/eslint/no-unstable-deps#rule-details If mutation and the use of mutate are in different files, then when I use mutation.mutate in deps, no error is displayed, but if they were in the same file, an error would be displayed. Your minimal, reproducible examplehttps://stackblitz.com/edit/tanstack-query-peqt34c7?file=src%2Findex.tsx Steps to reproduce// File 1
export const useMutation = () => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (payload: string[]) => update(payload),
onMutate: async () => {
await queryClient.cancelQueries({ queryKey: 'test' })
const previousTest = queryClient.getQueryData('test')
return { previousTest }
},
onSuccess: (data) => {
queryClient.setQueryData('test', (old: ExampleType[]) =>
old.map((test) => (test._id === data._id ? data : test))
)
},
onError: (_err, _var, context) => {
queryClient.setQueryData('test', context?.previousTest)
},
})
} // File 2
const mutation = useMutation()
const handleUpdate = useCallback(
(changedItems: ExampleType[]) => {
const orderedIds = changedItems.map((item) => item._id)
mutation.mutate(orderedIds)
},
[mutation] // Should give an warning that mutation is not stable
) Expected behaviorShould report warn when using mutation in deps How often does this bug happen?Every time Screenshots or VideosNo response Platform
Tanstack Query adapterreact-query TanStack Query versionv5.90.2 TypeScript versionv5.9.3 Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
we don’t track usages across files, I think this would be pretty hard to achieve with linting alone. |
Beta Was this translation helpful? Give feedback.
we don’t track usages across files, I think this would be pretty hard to achieve with linting alone.