Skip to content

Make QueryKey consistently an Array #2919

Closed
@TkDodo

Description

@TkDodo

When we pass the queryKey to the QueryFunctionContext, we make sure that it is an Array. This is great for global query functions, because you can just work with an Array<unknown> on type level.

However, in other situations where we provide the whole Query, accessing query.queryKey will still be string|Array<unknown>. For example, when using the predicate filter:

  queryClient.invalidateQueries({
    predicate: (query) => query.queryKey...
  })

here, it is not guaranteed that query.queryKey is an Array, so it's harder to work with

Proposed solution

only allow Arrays for QueryKeys (and for MutationKeys as well)

a codemod would be very good for this. we could let it run over all our examples, and we'd also need to update everything in the docs.


things to take care about:

  • useQuery
  • useInfiniteQuery
  • useMutation
  • queryCache.find
  • mutationCache.find
  • all methods on queryClient

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions