Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

parameter-is-object-expression.output.tsx

175 lines5.0 KB

1import * as React from 'react'
2import { useMutation, useQuery, useQueryClient } from 'react-query'
3​
4const options = {}
5​
6export const ExampleWithStringLiteral = () => {
7 useQuery({
8 queryKey: ['todos'],
9 exact: true
10 }, options)
11 useMutation({
12 mutationKey: ['todos'],
13 exact: true
14 }, options)
15 // QueryClient methods
16 // --- Instantiated hook call.
17 const queryClient = useQueryClient()
18 queryClient.cancelQueries({
19 queryKey: ['todos'],
20 exact: true
21 }, options)
22 // --- Direct hook call.
23 useQueryClient().cancelQueries({
24 queryKey: ['todos'],
25 exact: true
26 }, options)
27​
28 return <div>Example Component</div>
30​
31export const ExampleWithStringLiteralIdentifier = () => {
32 const stringLiteralKey = 'todos'
33 useQuery({
34 queryKey: [stringLiteralKey],
35 exact: true
36 }, options)
37 useMutation({
38 mutationKey: [stringLiteralKey],
39 exact: true
40 }, options)
41 // QueryClient methods
42 // --- Instantiated hook call.
43 const queryClient = useQueryClient()
44 queryClient.cancelQueries({
45 queryKey: [stringLiteralKey],
46 exact: true
47 }, options)
48 // --- Direct hook call.
49 useQueryClient().cancelQueries({
50 queryKey: [stringLiteralKey],
51 exact: true
52 }, options)
53​
54 return <div>Example Component</div>
56​
57export const ExampleWithTemplateLiteral = () => {
58 useQuery({
59 queryKey: [`todos`],
60 exact: true
61 }, options)
62 useMutation({
63 mutationKey: [`todos`],
64 exact: true
65 }, options)
66 // QueryClient methods
67 // --- Instantiated hook call.
68 const queryClient = useQueryClient()
69 queryClient.cancelQueries({
70 queryKey: [`todos`],
71 exact: true
72 }, options)
73 // --- Direct hook call.
74 useQueryClient().cancelQueries({
75 queryKey: [`todos`],
76 exact: true
77 }, options)
78​
79 return <div>Example Component</div>
81​
82export const ExampleWithTemplateLiteralIdentifier = () => {
83 const templateLiteralKey = `todos`
84 useQuery({
85 queryKey: [templateLiteralKey],
86 exact: true
87 }, options)
88 useMutation({
89 mutationKey: [templateLiteralKey],
90 exact: true
91 }, options)
92 // QueryClient methods
93 // --- Instantiated hook call.
94 const queryClient = useQueryClient()
95 queryClient.cancelQueries({
96 queryKey: [templateLiteralKey],
97 exact: true
98 }, options)
99 // --- Direct hook call.
100 useQueryClient().cancelQueries({
101 queryKey: [templateLiteralKey],
102 exact: true
103 }, options)
104​
105 return <div>Example Component</div>
107​
108export const ExampleWithArrayExpression = () => {
109 useQuery({ queryKey: ['todos'], exact: true }, options)
110 useMutation({ mutationKey: ['todos'], exact: true }, options)
111 // QueryClient methods
112 // --- Instantiated hook call.
113 const queryClient = useQueryClient()
114 queryClient.cancelQueries({ queryKey: ['todos'], exact: true }, options)
115 // --- Direct hook call.
116 useQueryClient().cancelQueries({ queryKey: ['todos'], exact: true }, options)
117​
118 return <div>Example Component</div>
120​
121export const ExampleWithArrayExpressionIdentifier = () => {
122 const arrayExpressionKey = ['todos']
123 useQuery({ queryKey: arrayExpressionKey, exact: true }, options)
124 useMutation({ mutationKey: arrayExpressionKey, exact: true }, options)
125 // QueryClient methods
126 // --- Instantiated hook call.
127 const queryClient = useQueryClient()
128 queryClient.cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
129 // --- Direct hook call.
130 useQueryClient().cancelQueries({ queryKey: arrayExpressionKey, exact: true }, options)
131​
132 return <div>Example Component</div>
134​
135export const ExampleWithUnknownIdentifier1 = () => {
136 const createKey = (id) => ['todos', id]
137 const createdKey1 = createKey(1)
138 useQuery({ queryKey: createdKey1, exact: true }, options)
139 useMutation({ mutationKey: createdKey1, exact: true }, options)
140 // QueryClient methods
141 // --- Instantiated hook call.
142 const queryClient = useQueryClient()
143 queryClient.cancelQueries({ queryKey: createdKey1, exact: true }, options)
144 // --- Direct hook call.
145 useQueryClient().cancelQueries({ queryKey: createdKey1, exact: true }, options)
146​
147 return <div>Example Component</div>
149​
150export const ExampleWithUnknownIdentifier2 = () => {
151 const createdKey2 = createKey()
152 useQuery({ queryKey: createdKey2, exact: true }, options)
153 useMutation({ mutationKey: createdKey2, exact: true }, options)
154 // QueryClient methods
155 // --- Instantiated hook call.
156 const queryClient = useQueryClient()
157 queryClient.cancelQueries({ queryKey: createdKey2, exact: true }, options)
158 // --- Direct hook call.
159 useQueryClient().cancelQueries({ queryKey: createdKey2, exact: true }, options)
160​
161 return <div>Example Component</div>
163​
164export const ExampleWithUnknownIdentifier3 = () => {
165 useQuery({ queryKey: unknownQueryKey, exact: true }, options)
166 useMutation({ mutationKey: unknownQueryKey, exact: true }, options)
167 // QueryClient methods
168 // --- Instantiated hook call.
169 const queryClient = useQueryClient()
170 queryClient.cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
171 // --- Direct hook call.
172 useQueryClient().cancelQueries({ queryKey: unknownQueryKey, exact: true }, options)
173​
174 return <div>Example Component</div>