Skip to content

eslint plugin exhaustive deps objects false positive #5088

Closed
@BATCOH

Description

@BATCOH

Describe the bug

After upgrade to v4.26.2 eslint considers some internal variables inside queryFn as dependencies.

export function useApi() {
  return useQuery({
    queryKey: ["api"], // Error: The following dependencies are missing in your queryKey: data[0].name
    queryFn: async () => {
      const response = await fetch(
        `https://jsonplaceholder.typicode.com/users`
      );
      const data = await response.json();
      return data[0].name;
    },
  });
}

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/loving-wildflower-7h6sz3?file=%2Fsrc%2FuseApi.ts&selection=%5B%7B%22endColumn%22%3A2%2C%22endLineNumber%22%3A14%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D

Steps to reproduce

  1. Open codesandbox exaple
  2. See the error

Expected behavior

No error for scoped variables

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

eslint: 8.35.0
@tanstack/react-query: 4.26.1
@tanstack/eslint-plugin-query: 4.26.2

TanStack Query version

4.26.1

TypeScript version

4.9.5

Additional context

Maybe, related: #5069 #5079

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