Skip to content

eslint exhaustive-deps labelling constant values in external functions as dependency #5446

@luizeboli

Description

@luizeboli

Describe the bug

Related to #5196

Incorrect exhaustive-deps error for constant values when using them in an external function to define the query

image
(ApiRoutes is an external enum)

Steps to reproduce

Use constants values in an external function outside useQuery

const Ab = 1

// This throws the error
function groupsQuery() {
  return {
    queryKey: ['get-groups'],
    queryFn: () => Ab,
  }
}

// This works
function useGroups() {
  return useQuery({
    queryKey: ['get-groups'],
    queryFn: () => Ab,
  })
}

Expected behavior

Constants used in external functions should not count as a dependency

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • VSCode

Tanstack Query adapter

react-query

TanStack Query version

v4.29.5

TypeScript version

No response

Additional context

Using @tanstack/eslint-plugin-query in v4.29.8

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