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

default.output.tsx

284 lines7.4 KB

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