Skip to content

eslint-plugin-query: false positive for factory functions that return an object #4476

@TkDodo

Description

@TkDodo
const getQuery = () => ({
  queryKey: ['foo'],
  queryFn: () => Promise.resolve(5)
})

return useQuery(getQuery())

⬆️ ESLint: Objects syntax for useQuery is preferred(@tanstack/query/prefer-query-object-syntax)

what's more dangerous, it even auto fixes this to:

return useQuery({ queryKey: getQuery() })

which is wrong.


As a workaround, we have to create a new object and spread:

useQuery({ ...getQuery() })

The wrong auto-fix is a big problem I think because it will convert working code to non-working code :/

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