Skip to content

eslint-plugin-query: exhaustive-deps does not suport queryFn() {} syntax #7202

@rodrigorm

Description

@rodrigorm

Describe the bug

Usage of the following syntax does not trigger an error from "@tanstack/query/exhaustive-deps":

const id = "foo";

useQuery({
  queryKey: ["deps"],
  queryFn() {
      return id;
  }
});

What I have found is this syntax trigger an error:

const id = "foo";

useQuery({
  queryKey: ["deps"],
  queryFn: () => {
      return id;
  }
});

Your minimal, reproducible example

https://codesandbox.io/p/devbox/fancy-lake-hymxyk

Steps to reproduce

  1. Go to https://codesandbox.io/p/devbox/fancy-lake-hymxyk
  2. Fork
  3. Open a new Terminal
  4. Run yarn eslint src/index.jsx

Expected behavior

Expected output:

yarn run v1.22.19
$ /workspace/node_modules/.bin/eslint src/index.jsx

/workspace/src/index.jsx
  25:5  error  The following dependencies are missing in your queryKey: endpoint  @tanstack/query/exhaustive-deps

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Any

Tanstack Query adapter

react-query

TanStack Query version

v5.28.6

TypeScript version

v5.3.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions