QueryKey
stableQuery key type definition
Type definition for query keys. Query keys are unique identifiers for queries and can be strings, arrays, or objects.
TypeQuery Key
Key Uniqueness
Query keys must be unique to identify different queries. Use descriptive and meaningful keys that clearly identify the data being fetched.
Signature
type QueryKey = string | readonly (string | number)[]
Parameters
string
stringSimple string identifier for the query.
readonly (string | number)[]
readonly (string | number)[]Readonly array of strings and numbers for hierarchical identification.
Behavior
Unique Identification
Query keys must be unique to identify different queries
Serializable
Query keys are serialized for cache storage and comparison
Hierarchical
Array and object keys support hierarchical identification
Type Safe
Full TypeScript support with proper type inference
Best Practices
Do's
- ✓Use descriptive and meaningful query keys
- ✓Use array keys for hierarchical identification
- ✓Use object keys for complex structured identification
- ✓Keep query keys consistent across your application
Don'ts
- ✗Don't use query keys that change on every render
- ✗Don't use complex objects that are hard to serialize
- ✗Don't use query keys that contain sensitive data
- ✗Don't use query keys that are too long or complex