query key

The array that names a piece of cached server data in TanStack Query, such as ["users", "detail", "10"].

In more detail

Keys are hierarchical, so invalidating ["posts"] also invalidates every key that starts with it. A key factory is a small object of functions that builds all keys for one resource, so no one hand-types a string and gets it wrong.

Example

detail: (id: string) => [...keys.all, "detail", id] as const

Related terms

Taught in

References