Query key factory
A query key factory is a shared set of functions that constructs consistent query keys from resource names and parameters. It prevents different screens from creating separate cache entries for the same data and makes prefix-based invalidation easier.
Minimal example
const restaurantKeys = {
all: ["restaurants"] as const,
search: (term: string) => [
"restaurants",
"search",
normalizeTerm(term),
] as const,
};Learn this concept
Lesson 4.19 · Resilient client patternsUsed in exercises
Exercise 4.22 · Restaurant search utilitiesRelatedQuery invalidation