Skip to content

false-positive with "static" dependencies #5185

@TkDodo

Description

@TkDodo

Sometimes, we have a static dependency that we read from e.g. react context, like an api:

const useFoo = () => {
  const api = useApi();
  return useQuery({
    queryKey: ['foo'],
    queryFn: () => api.fetchFoo(),
  })
}

this api is injected via react-context, but it's stable and not really changing. We mainly have it context to provide a different API for testing.

The eslint-plugin-query complains here rightfully that api should be added to the QueryKey, but we can't really do that - it's an axios instance that is not serializable. It's also not intended to be added to the key. For us, it's essentially the same as:

import api from 'api'

const useFoo = () => {
  return useQuery({
    queryKey: ['foo'],
    queryFn: () => api.fetchFoo(),
  })
}

Of course, the linter doesn't know that this dependency is "stable". Maybe we could have an option on the eslint plugin that defines known exceptions? @Newbie012 what do you think?

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