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

named.output.tsx

290 lines7.8 KB

1import * as React from 'react'
2import axios from 'axios'
3import {
4 keepPreviousData,
5 QueryClient as RenamedQueryClient,
6 useQueries as useRenamedUseQueries,
7 useQuery as useRenamedUseQuery,
8 useQueryClient as useRenamedUseQueryClient,
9} from '@tanstack/react-query';
10​
11type Post = {
12 id: number
13 title: string
14 body: string
16​
17const queryFn = async (): Promise<Array<Post>> => {
18 const { data } = await axios.get(
19 'https://jsonplaceholder.typicode.com/posts',
20 )
21 return data
23​
24/**
25 * The object expression has a `keepPreviousData` property with value `true`, so the codemod should transform
26 * this usage.
27 */
28export const Example1 = () => {
29 const { data } = useRenamedUseQuery({
30 queryKey: ['posts'],
31 queryFn: queryFn,
32 placeholderData: keepPreviousData
33 })
34​
35 return <div>{JSON.stringify(data)}</div>
37​
38/**
39 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a function.
40 * The codemod shouldn't transform this case, only warn the user about the manual migration.
41 */
42export const Example2 = () => {
43 const { data } = useRenamedUseQuery({
44 queryKey: ['posts'],
45 queryFn: queryFn,
46 keepPreviousData: true,
47 placeholderData: () => previousData
48 })
49​
50 return <div>{JSON.stringify(data)}</div>
52​
53/**
54 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a string.
55 * The codemod shouldn't transform this case, only warn the user about the manual migration.
56 */
57export const Example3 = () => {
58 const { data } = useRenamedUseQueries({
59 queryKey: ['posts'],
60 queryFn: queryFn,
61 keepPreviousData: true,
62 placeholderData: 'somePlaceholderData'
63 })
64​
65 return <div>{JSON.stringify(data)}</div>
67​
68/**
69 * The object expression has a `keepPreviousData` property with value `false`.
70 * The codemod shouldn't transform this case, only warn the user about the manual migration.
71 */
72export const Example4 = () => {
73 const { data } = useRenamedUseQueries({
74 queryKey: ['posts'],
75 queryFn: queryFn,
76 keepPreviousData: false,
77 })
78​
79 return <div>{JSON.stringify(data)}</div>
81​
82/**
83 * The object expression has a `keepPreviousData` property with which is an identifier.
84 * The codemod shouldn't transform this case, only warn the user about the manual migration.
85 */
86export const Example5 = () => {
87 const keepPreviousDataIdentifier = false
88 const { data } = useRenamedUseQueries({
89 queryKey: ['posts'],
90 queryFn: queryFn,
91 keepPreviousData: keepPreviousDataIdentifier,
92 placeholderData: () => previousData
93 })
94​
95 return <div>{JSON.stringify(data)}</div>
97​
98/**
99 * The object expression has a `keepPreviousData` property with value `true`, so the codemod should transform
100 * this usage.
101 */
102export const Example6 = () => {
103 const queryClient = new RenamedQueryClient()
104​
105 queryClient.setQueryDefaults(['key'], {
106 placeholderData: keepPreviousData
107 })
108​
109 useRenamedUseQueryClient().setQueryDefaults(['key'], {
110 placeholderData: keepPreviousData
111 })
112​
113 const anotherQueryClient = useRenamedUseQueryClient()
114​
115 anotherQueryClient.setQueryDefaults(['key'], {
116 placeholderData: keepPreviousData
117 })
119​
120/**
121 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a function.
122 * The codemod shouldn't transform this case, only warn the user about the manual migration.
123 */
124export const Example7 = () => {
125 const queryClient = new RenamedQueryClient()
126​
127 queryClient.setQueryDefaults(['key'], {
128 keepPreviousData: true,
129 placeholderData: () => previousData
130 })
131​
132 useRenamedUseQueryClient().setQueryDefaults(['key'], {
133 keepPreviousData: true,
134 placeholderData: () => previousData
135 })
136​
137 const anotherQueryClient = useRenamedUseQueryClient()
138​
139 anotherQueryClient.setQueryDefaults(['key'], {
140 keepPreviousData: true,
141 placeholderData: () => previousData
142 })
144​
145/**
146 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a string.
147 * The codemod shouldn't transform this case, only warn the user about the manual migration.
148 */
149export const Example8 = () => {
150 const queryClient = new RenamedQueryClient()
151​
152 queryClient.setQueryDefaults(['key'], {
153 keepPreviousData: true,
154 placeholderData: 'somePlaceholderData'
155 })
156​
157 useRenamedUseQueryClient().setQueryDefaults(['key'], {
158 keepPreviousData: true,
159 placeholderData: 'somePlaceholderData'
160 })
161​
162 const anotherQueryClient = useRenamedUseQueryClient()
163​
164 anotherQueryClient.setQueryDefaults(['key'], {
165 keepPreviousData: true,
166 placeholderData: 'somePlaceholderData'
167 })
169​
170/**
171 * The object expression has a `keepPreviousData` property with value `false`.
172 * The codemod shouldn't transform this case, only warn the user about the manual migration.
173 */
174export const Example9 = () => {
175 const queryClient = new RenamedQueryClient()
176​
177 queryClient.setQueryDefaults(['key'], {
178 keepPreviousData: false,
179 })
180​
181 useRenamedUseQueryClient().setQueryDefaults(['key'], {
182 keepPreviousData: false,
183 })
184​
185 const anotherQueryClient = useRenamedUseQueryClient()
186​
187 anotherQueryClient.setQueryDefaults(['key'], {
188 keepPreviousData: false,
189 })
191​
192/**
193 * The object expression has a `keepPreviousData` property with which is an identifier.
194 * The codemod shouldn't transform this case, only warn the user about the manual migration.
195 */
196export const Example10 = () => {
197 const queryClient = new RenamedQueryClient()
198 const keepPreviousDataIdentifier = false
199​
200 queryClient.setQueryDefaults(['key'], {
201 keepPreviousData: keepPreviousDataIdentifier,
202 placeholderData: () => previousData
203 })
204​
205 useRenamedUseQueryClient().setQueryDefaults(['key'], {
206 keepPreviousData: keepPreviousDataIdentifier,
207 placeholderData: () => previousData
208 })
209​
210 const anotherQueryClient = useRenamedUseQueryClient()
211​
212 anotherQueryClient.setQueryDefaults(['key'], {
213 keepPreviousData: keepPreviousDataIdentifier,
214 placeholderData: () => previousData
215 })
217​
218/**
219 * The object expression has a `keepPreviousData` property with value `true`, so the codemod should transform
220 * this usage.
221 */
222export const Example11 = () => {
223 new RenamedQueryClient({
224 defaultOptions: {
225 queries: {
226 placeholderData: keepPreviousData
227 }
228 }
229 })
231​
232/**
233 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a function.
234 * The codemod shouldn't transform this case, only warn the user about the manual migration.
235 */
236export const Example12 = () => {
237 new RenamedQueryClient({
238 defaultOptions: {
239 queries: {
240 keepPreviousData: true,
241 placeholderData: () => previousData
242 }
243 }
244 })
246​
247/**
248 * The object expression has a `keepPreviousData` property with value `true`, but the `placeholderData` is a string.
249 * The codemod shouldn't transform this case, only warn the user about the manual migration.
250 */
251export const Example13 = () => {
252 new RenamedQueryClient({
253 defaultOptions: {
254 queries: {
255 keepPreviousData: true,
256 placeholderData: 'somePlaceholderData'
257 }
258 }
259 })
261​
262/**
263 * The object expression has a `keepPreviousData` property with value `false`.
264 * The codemod shouldn't transform this case, only warn the user about the manual migration.
265 */
266export const Example14 = () => {
267 new RenamedQueryClient({
268 defaultOptions: {
269 queries: {
270 keepPreviousData: false,
271 }
272 }
273 })
275​
276/**
277 * The object expression has a `keepPreviousData` property with which is an identifier.
278 * The codemod shouldn't transform this case, only warn the user about the manual migration.
279 */
280export const Example15 = () => {
281 const keepPreviousDataIdentifier = false
282 new RenamedQueryClient({
283 defaultOptions: {
284 queries: {
285 keepPreviousData: keepPreviousDataIdentifier,
286 placeholderData: () => previousData
287 }
288 }
289 })