Open History to see the last commit
1---
2id: query-keys
3title: Query Keys
4ref: docs/framework/react/guides/query-keys.md
5#todo: exhaustive-deps is at least for now React-only
6---
7β
8[//]: # 'Example'
9β
10```ts
11// A list of todos
12injectQuery(() => ({ queryKey: ['todos'], ... }))
13β
14// Something else, whatever!
15injectQuery(() => ({ queryKey: ['something', 'special'], ... }))
16```
17β
18[//]: # 'Example'
19[//]: # 'Example2'
20β
21```ts
22// An individual todo
23injectQuery(() => ({queryKey: ['todo', 5], ...}))
24β
25// An individual todo in a "preview" format
26injectQuery(() => ({queryKey: ['todo', 5, {preview: true}], ...}))
27β
28// A list of todos that are "done"
29injectQuery(() => ({queryKey: ['todos', {type: 'done'}], ...}))
30```
31β
32[//]: # 'Example2'
33[//]: # 'Example3'
34β
35```ts
36injectQuery(() => ({ queryKey: ['todos', { status, page }], ... }))
37injectQuery(() => ({ queryKey: ['todos', { page, status }], ...}))
38injectQuery(() => ({ queryKey: ['todos', { page, status, other: undefined }], ... }))
39```
40β
41[//]: # 'Example3'
42[//]: # 'Example4'
43β
44```ts
45injectQuery(() => ({ queryKey: ['todos', status, page], ... }))
46injectQuery(() => ({ queryKey: ['todos', page, status], ...}))
47injectQuery(() => ({ queryKey: ['todos', undefined, page, status], ...}))
48```
49β
50[//]: # 'Example4'
51[//]: # 'Example5'
52β
53```ts
54todoId = signal(-1)
55β
56injectQuery(() => ({
57 enabled: todoId() > 0,
58 queryKey: ['todos', todoId()],
59 queryFn: () => fetchTodoById(todoId()),
60}))
61```
62β
63[//]: # 'Example5'
64[//]: # 'Materials'
65[//]: # 'Materials'