@tanstack/react-query 4.24.9 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/build/lib/HydrationBoundary.d.ts +9 -0
  2. package/build/lib/{Hydrate.esm.js → HydrationBoundary.esm.js} +14 -17
  3. package/build/lib/HydrationBoundary.esm.js.map +1 -0
  4. package/build/lib/{Hydrate.js → HydrationBoundary.js} +17 -24
  5. package/build/lib/HydrationBoundary.js.map +1 -0
  6. package/build/lib/{Hydrate.mjs → HydrationBoundary.mjs} +14 -17
  7. package/build/lib/HydrationBoundary.mjs.map +1 -0
  8. package/build/lib/QueryClientProvider.d.ts +4 -19
  9. package/build/lib/QueryClientProvider.esm.js +11 -46
  10. package/build/lib/QueryClientProvider.esm.js.map +1 -1
  11. package/build/lib/QueryClientProvider.js +14 -52
  12. package/build/lib/QueryClientProvider.js.map +1 -1
  13. package/build/lib/QueryClientProvider.mjs +11 -46
  14. package/build/lib/QueryClientProvider.mjs.map +1 -1
  15. package/build/lib/QueryErrorResetBoundary.esm.js +7 -2
  16. package/build/lib/QueryErrorResetBoundary.esm.js.map +1 -1
  17. package/build/lib/QueryErrorResetBoundary.js +10 -8
  18. package/build/lib/QueryErrorResetBoundary.js.map +1 -1
  19. package/build/lib/QueryErrorResetBoundary.mjs +7 -2
  20. package/build/lib/QueryErrorResetBoundary.mjs.map +1 -1
  21. package/build/lib/__tests__/useQuery.types.test.d.ts +1 -2
  22. package/build/lib/__tests__/utils.d.ts +7 -10
  23. package/build/lib/errorBoundaryUtils.d.ts +3 -3
  24. package/build/lib/errorBoundaryUtils.esm.js +3 -3
  25. package/build/lib/errorBoundaryUtils.esm.js.map +1 -1
  26. package/build/lib/errorBoundaryUtils.js +6 -9
  27. package/build/lib/errorBoundaryUtils.js.map +1 -1
  28. package/build/lib/errorBoundaryUtils.mjs +3 -3
  29. package/build/lib/errorBoundaryUtils.mjs.map +1 -1
  30. package/build/lib/index.d.ts +4 -5
  31. package/build/lib/index.esm.js +3 -4
  32. package/build/lib/index.esm.js.map +1 -1
  33. package/build/lib/index.js +6 -9
  34. package/build/lib/index.js.map +1 -1
  35. package/build/lib/index.mjs +3 -4
  36. package/build/lib/index.mjs.map +1 -1
  37. package/build/lib/isRestoring.esm.js.map +1 -1
  38. package/build/lib/isRestoring.js +3 -6
  39. package/build/lib/isRestoring.js.map +1 -1
  40. package/build/lib/isRestoring.mjs.map +1 -1
  41. package/build/lib/suspense.esm.js +5 -5
  42. package/build/lib/suspense.esm.js.map +1 -1
  43. package/build/lib/suspense.js +5 -7
  44. package/build/lib/suspense.js.map +1 -1
  45. package/build/lib/suspense.mjs +5 -5
  46. package/build/lib/suspense.mjs.map +1 -1
  47. package/build/lib/types.d.ts +14 -22
  48. package/build/lib/useBaseQuery.d.ts +2 -2
  49. package/build/lib/useBaseQuery.esm.js +15 -18
  50. package/build/lib/useBaseQuery.esm.js.map +1 -1
  51. package/build/lib/useBaseQuery.js +18 -24
  52. package/build/lib/useBaseQuery.js.map +1 -1
  53. package/build/lib/useBaseQuery.mjs +15 -18
  54. package/build/lib/useBaseQuery.mjs.map +1 -1
  55. package/build/lib/useInfiniteQuery.d.ts +2 -4
  56. package/build/lib/useInfiniteQuery.esm.js +4 -4
  57. package/build/lib/useInfiniteQuery.esm.js.map +1 -1
  58. package/build/lib/useInfiniteQuery.js +3 -5
  59. package/build/lib/useInfiniteQuery.js.map +1 -1
  60. package/build/lib/useInfiniteQuery.mjs +4 -4
  61. package/build/lib/useInfiniteQuery.mjs.map +1 -1
  62. package/build/lib/useIsFetching.d.ts +2 -7
  63. package/build/lib/useIsFetching.esm.js +5 -9
  64. package/build/lib/useIsFetching.esm.js.map +1 -1
  65. package/build/lib/useIsFetching.js +7 -14
  66. package/build/lib/useIsFetching.js.map +1 -1
  67. package/build/lib/useIsFetching.mjs +5 -9
  68. package/build/lib/useIsFetching.mjs.map +1 -1
  69. package/build/lib/useMutation.d.ts +2 -5
  70. package/build/lib/useMutation.esm.js +12 -14
  71. package/build/lib/useMutation.esm.js.map +1 -1
  72. package/build/lib/useMutation.js +14 -19
  73. package/build/lib/useMutation.js.map +1 -1
  74. package/build/lib/useMutation.mjs +12 -14
  75. package/build/lib/useMutation.mjs.map +1 -1
  76. package/build/lib/useMutationState.d.ts +8 -0
  77. package/build/lib/useMutationState.esm.js +37 -0
  78. package/build/lib/useMutationState.esm.js.map +1 -0
  79. package/build/lib/useMutationState.js +59 -0
  80. package/build/lib/useMutationState.js.map +1 -0
  81. package/build/lib/useMutationState.mjs +37 -0
  82. package/build/lib/useMutationState.mjs.map +1 -0
  83. package/build/lib/useQueries.d.ts +9 -7
  84. package/build/lib/useQueries.esm.js +16 -27
  85. package/build/lib/useQueries.esm.js.map +1 -1
  86. package/build/lib/useQueries.js +19 -33
  87. package/build/lib/useQueries.js.map +1 -1
  88. package/build/lib/useQueries.mjs +16 -27
  89. package/build/lib/useQueries.mjs.map +1 -1
  90. package/build/lib/useQuery.d.ts +9 -21
  91. package/build/lib/useQuery.esm.js +5 -4
  92. package/build/lib/useQuery.esm.js.map +1 -1
  93. package/build/lib/useQuery.js +4 -5
  94. package/build/lib/useQuery.js.map +1 -1
  95. package/build/lib/useQuery.mjs +5 -4
  96. package/build/lib/useQuery.mjs.map +1 -1
  97. package/build/lib/utils.d.ts +1 -1
  98. package/build/lib/utils.esm.js +5 -6
  99. package/build/lib/utils.esm.js.map +1 -1
  100. package/build/lib/utils.js +5 -8
  101. package/build/lib/utils.js.map +1 -1
  102. package/build/lib/utils.mjs +5 -6
  103. package/build/lib/utils.mjs.map +1 -1
  104. package/build/umd/index.development.js +1007 -1826
  105. package/build/umd/index.development.js.map +1 -1
  106. package/build/umd/index.production.js +1 -1
  107. package/build/umd/index.production.js.map +1 -1
  108. package/package.json +6 -18
  109. package/src/{Hydrate.tsx → HydrationBoundary.tsx} +17 -18
  110. package/src/QueryClientProvider.tsx +11 -65
  111. package/src/__tests__/{Hydrate.test.tsx → HydrationBoundary.test.tsx} +89 -77
  112. package/src/__tests__/QueryClientProvider.test.tsx +33 -147
  113. package/src/__tests__/QueryResetErrorBoundary.test.tsx +118 -85
  114. package/src/__tests__/ssr-hydration.test.tsx +27 -33
  115. package/src/__tests__/ssr.test.tsx +23 -9
  116. package/src/__tests__/suspense.test.tsx +194 -171
  117. package/src/__tests__/useInfiniteQuery.test.tsx +249 -494
  118. package/src/__tests__/useInfiniteQuery.type.test.tsx +131 -0
  119. package/src/__tests__/useIsFetching.test.tsx +65 -108
  120. package/src/__tests__/useMutation.test.tsx +200 -268
  121. package/src/__tests__/useMutationState.test.tsx +284 -0
  122. package/src/__tests__/useQueries.test.tsx +43 -347
  123. package/src/__tests__/useQuery.test.tsx +890 -686
  124. package/src/__tests__/useQuery.types.test.tsx +23 -24
  125. package/src/__tests__/utils.tsx +14 -23
  126. package/src/errorBoundaryUtils.ts +5 -10
  127. package/src/index.ts +4 -7
  128. package/src/types.ts +33 -38
  129. package/src/useBaseQuery.ts +7 -7
  130. package/src/useInfiniteQuery.ts +12 -77
  131. package/src/useIsFetching.ts +8 -20
  132. package/src/useMutation.ts +8 -66
  133. package/src/useMutationState.ts +81 -0
  134. package/src/useQueries.ts +29 -21
  135. package/src/useQuery.ts +27 -104
  136. package/src/utils.ts +5 -5
  137. package/build/lib/Hydrate.d.ts +0 -10
  138. package/build/lib/Hydrate.esm.js.map +0 -1
  139. package/build/lib/Hydrate.js.map +0 -1
  140. package/build/lib/Hydrate.mjs.map +0 -1
  141. package/build/lib/reactBatchedUpdates.d.ts +0 -2
  142. package/build/lib/reactBatchedUpdates.esm.js +0 -6
  143. package/build/lib/reactBatchedUpdates.esm.js.map +0 -1
  144. package/build/lib/reactBatchedUpdates.js +0 -30
  145. package/build/lib/reactBatchedUpdates.js.map +0 -1
  146. package/build/lib/reactBatchedUpdates.mjs +0 -6
  147. package/build/lib/reactBatchedUpdates.mjs.map +0 -1
  148. package/build/lib/reactBatchedUpdates.native.d.ts +0 -2
  149. package/build/lib/reactBatchedUpdates.native.esm.js +0 -2
  150. package/build/lib/reactBatchedUpdates.native.esm.js.map +0 -1
  151. package/build/lib/reactBatchedUpdates.native.js +0 -13
  152. package/build/lib/reactBatchedUpdates.native.js.map +0 -1
  153. package/build/lib/reactBatchedUpdates.native.mjs +0 -2
  154. package/build/lib/reactBatchedUpdates.native.mjs.map +0 -1
  155. package/build/lib/setBatchUpdatesFn.esm.js +0 -5
  156. package/build/lib/setBatchUpdatesFn.esm.js.map +0 -1
  157. package/build/lib/setBatchUpdatesFn.js +0 -7
  158. package/build/lib/setBatchUpdatesFn.js.map +0 -1
  159. package/build/lib/setBatchUpdatesFn.mjs +0 -5
  160. package/build/lib/setBatchUpdatesFn.mjs.map +0 -1
  161. package/build/lib/useIsMutating.d.ts +0 -7
  162. package/build/lib/useIsMutating.esm.js +0 -16
  163. package/build/lib/useIsMutating.esm.js.map +0 -1
  164. package/build/lib/useIsMutating.js +0 -40
  165. package/build/lib/useIsMutating.js.map +0 -1
  166. package/build/lib/useIsMutating.mjs +0 -16
  167. package/build/lib/useIsMutating.mjs.map +0 -1
  168. package/build/lib/useSyncExternalStore.d.ts +0 -2
  169. package/build/lib/useSyncExternalStore.esm.js +0 -7
  170. package/build/lib/useSyncExternalStore.esm.js.map +0 -1
  171. package/build/lib/useSyncExternalStore.js +0 -11
  172. package/build/lib/useSyncExternalStore.js.map +0 -1
  173. package/build/lib/useSyncExternalStore.mjs +0 -7
  174. package/build/lib/useSyncExternalStore.mjs.map +0 -1
  175. package/build/lib/useSyncExternalStore.native.d.ts +0 -2
  176. package/build/lib/useSyncExternalStore.native.esm.js +0 -2
  177. package/build/lib/useSyncExternalStore.native.esm.js.map +0 -1
  178. package/build/lib/useSyncExternalStore.native.js +0 -13
  179. package/build/lib/useSyncExternalStore.native.js.map +0 -1
  180. package/build/lib/useSyncExternalStore.native.mjs +0 -2
  181. package/build/lib/useSyncExternalStore.native.mjs.map +0 -1
  182. package/codemods/v4/key-transformation.js +0 -138
  183. package/codemods/v4/replace-import-specifier.js +0 -25
  184. package/codemods/v4/utils/index.js +0 -166
  185. package/codemods/v4/utils/replacers/key-replacer.js +0 -160
  186. package/codemods/v4/utils/transformers/query-cache-transformer.js +0 -115
  187. package/codemods/v4/utils/transformers/query-client-transformer.js +0 -49
  188. package/codemods/v4/utils/transformers/use-query-like-transformer.js +0 -32
  189. package/codemods/v4/utils/unprocessable-key-error.js +0 -8
  190. package/src/__tests__/useIsMutating.test.tsx +0 -259
  191. package/src/reactBatchedUpdates.native.ts +0 -4
  192. package/src/reactBatchedUpdates.ts +0 -2
  193. package/src/setBatchUpdatesFn.ts +0 -4
  194. package/src/useIsMutating.ts +0 -39
  195. package/src/useSyncExternalStore.native.ts +0 -5
  196. package/src/useSyncExternalStore.ts +0 -4
  197. /package/build/lib/__tests__/{Hydrate.test.d.ts → HydrationBoundary.test.d.ts} +0 -0
  198. /package/build/lib/__tests__/{useIsMutating.test.d.ts → useInfiniteQuery.type.test.d.ts} +0 -0
  199. /package/build/lib/{setBatchUpdatesFn.d.ts → __tests__/useMutationState.test.d.ts} +0 -0
@@ -0,0 +1,131 @@
1
+ import type { InfiniteData } from '@tanstack/query-core'
2
+ import { QueryClient } from '@tanstack/query-core'
3
+ import { useInfiniteQuery } from '../useInfiniteQuery'
4
+ import { useQuery } from '../useQuery'
5
+ import type { Expect, Equal } from './utils'
6
+ import { doNotExecute } from './utils'
7
+
8
+ describe('pageParam', () => {
9
+ it('defaultPageParam should define type of param passed to queryFunctionContext', () => {
10
+ doNotExecute(() => {
11
+ useInfiniteQuery({
12
+ queryKey: ['key'],
13
+ queryFn: ({ pageParam }) => {
14
+ const result: Expect<Equal<number, typeof pageParam>> = true
15
+ return result
16
+ },
17
+ defaultPageParam: 1,
18
+ getNextPageParam: () => undefined,
19
+ })
20
+ })
21
+ })
22
+
23
+ it('there should be no pageParam passed to queryFn of useQuery', () => {
24
+ doNotExecute(() => {
25
+ useQuery({
26
+ queryKey: ['key'],
27
+ // @ts-expect-error there should be no pageParam passed to queryFn of useQuery
28
+ queryFn: ({ pageParam }) => {
29
+ return String(pageParam)
30
+ },
31
+ })
32
+ })
33
+ })
34
+
35
+ it('defaultPageParam should define type of param passed to queryFunctionContext for fetchInfiniteQuery', () => {
36
+ doNotExecute(() => {
37
+ const queryClient = new QueryClient()
38
+ queryClient.fetchInfiniteQuery({
39
+ queryKey: ['key'],
40
+ queryFn: ({ pageParam }) => {
41
+ const result: Expect<Equal<number, typeof pageParam>> = true
42
+ return result
43
+ },
44
+ defaultPageParam: 1,
45
+ })
46
+ })
47
+ })
48
+
49
+ it('defaultPageParam should define type of param passed to queryFunctionContext for prefetchInfiniteQuery', () => {
50
+ doNotExecute(() => {
51
+ const queryClient = new QueryClient()
52
+ queryClient.prefetchInfiniteQuery({
53
+ queryKey: ['key'],
54
+ queryFn: ({ pageParam }) => {
55
+ const result: Expect<Equal<number, typeof pageParam>> = true
56
+ return result
57
+ },
58
+ defaultPageParam: 1,
59
+ })
60
+ })
61
+ })
62
+ })
63
+
64
+ describe('select', () => {
65
+ it('should still return paginated data if no select result', () => {
66
+ doNotExecute(() => {
67
+ const infiniteQuery = useInfiniteQuery({
68
+ queryKey: ['key'],
69
+ queryFn: ({ pageParam }) => {
70
+ return pageParam * 5
71
+ },
72
+ defaultPageParam: 1,
73
+ getNextPageParam: () => undefined,
74
+ })
75
+
76
+ const result: Expect<
77
+ Equal<InfiniteData<number> | undefined, (typeof infiniteQuery)['data']>
78
+ > = true
79
+ return result
80
+ })
81
+ })
82
+
83
+ it('should be able to transform data to arbitrary result', () => {
84
+ doNotExecute(() => {
85
+ const infiniteQuery = useInfiniteQuery({
86
+ queryKey: ['key'],
87
+ queryFn: ({ pageParam }) => {
88
+ return pageParam * 5
89
+ },
90
+ defaultPageParam: 1,
91
+ getNextPageParam: () => undefined,
92
+ select: (data) => {
93
+ const result: Expect<Equal<InfiniteData<number>, typeof data>> = true
94
+ return result
95
+ },
96
+ })
97
+
98
+ const result: Expect<
99
+ Equal<true | undefined, (typeof infiniteQuery)['data']>
100
+ > = true
101
+ return result
102
+ })
103
+ })
104
+ it('should pass transformed data to onSuccess', () => {
105
+ doNotExecute(() => {
106
+ const infiniteQuery = useInfiniteQuery({
107
+ queryKey: ['key'],
108
+ queryFn: ({ pageParam }) => {
109
+ return pageParam * 5
110
+ },
111
+ defaultPageParam: 1,
112
+ getNextPageParam: () => undefined,
113
+ select: (data) => {
114
+ return {
115
+ ...data,
116
+ pages: data.pages.map((page) => page.toString()),
117
+ }
118
+ },
119
+ onSuccess: (data) => {
120
+ const result: Expect<Equal<InfiniteData<string>, typeof data>> = true
121
+ doNotExecute(() => result)
122
+ },
123
+ })
124
+
125
+ const result: Expect<
126
+ Equal<InfiniteData<string> | undefined, (typeof infiniteQuery)['data']>
127
+ > = true
128
+ return result
129
+ })
130
+ })
131
+ })
@@ -1,6 +1,5 @@
1
- import { fireEvent, waitFor } from '@testing-library/react'
1
+ import { fireEvent, render, waitFor } from '@testing-library/react'
2
2
  import * as React from 'react'
3
- import { ErrorBoundary } from 'react-error-boundary'
4
3
 
5
4
  import {
6
5
  createQueryClient,
@@ -9,7 +8,6 @@ import {
9
8
  setActTimeout,
10
9
  sleep,
11
10
  } from './utils'
12
- import type { QueryClient } from '..'
13
11
  import { QueryCache, useIsFetching, useQuery } from '..'
14
12
 
15
13
  describe('useIsFetching', () => {
@@ -27,16 +25,14 @@ describe('useIsFetching', () => {
27
25
  function Query() {
28
26
  const [ready, setReady] = React.useState(false)
29
27
 
30
- useQuery(
31
- key,
32
- async () => {
28
+ useQuery({
29
+ queryKey: key,
30
+ queryFn: async () => {
33
31
  await sleep(50)
34
32
  return 'test'
35
33
  },
36
- {
37
- enabled: ready,
38
- },
39
- )
34
+ enabled: ready,
35
+ })
40
36
 
41
37
  return <button onClick={() => setReady(true)}>setReady</button>
42
38
  }
@@ -74,17 +70,23 @@ describe('useIsFetching', () => {
74
70
  }
75
71
 
76
72
  function FirstQuery() {
77
- useQuery(key1, async () => {
78
- await sleep(100)
79
- return 'data'
73
+ useQuery({
74
+ queryKey: key1,
75
+ queryFn: async () => {
76
+ await sleep(100)
77
+ return 'data'
78
+ },
80
79
  })
81
80
  return null
82
81
  }
83
82
 
84
83
  function SecondQuery() {
85
- useQuery(key2, async () => {
86
- await sleep(100)
87
- return 'data'
84
+ useQuery({
85
+ queryKey: key2,
86
+ queryFn: async () => {
87
+ await sleep(100)
88
+ return 'data'
89
+ },
88
90
  })
89
91
  return null
90
92
  }
@@ -119,24 +121,30 @@ describe('useIsFetching', () => {
119
121
  const isFetchings: number[] = []
120
122
 
121
123
  function One() {
122
- useQuery(key1, async () => {
123
- await sleep(10)
124
- return 'test'
124
+ useQuery({
125
+ queryKey: key1,
126
+ queryFn: async () => {
127
+ await sleep(10)
128
+ return 'test'
129
+ },
125
130
  })
126
131
  return null
127
132
  }
128
133
 
129
134
  function Two() {
130
- useQuery(key2, async () => {
131
- await sleep(20)
132
- return 'test'
135
+ useQuery({
136
+ queryKey: key2,
137
+ queryFn: async () => {
138
+ await sleep(20)
139
+ return 'test'
140
+ },
133
141
  })
134
142
  return null
135
143
  }
136
144
 
137
145
  function Page() {
138
146
  const [started, setStarted] = React.useState(false)
139
- const isFetching = useIsFetching(key1)
147
+ const isFetching = useIsFetching({ queryKey: key1 })
140
148
 
141
149
  isFetchings.push(isFetching)
142
150
 
@@ -164,101 +172,51 @@ describe('useIsFetching', () => {
164
172
  expect(isFetchings).toEqual(expect.not.arrayContaining([2]))
165
173
  })
166
174
 
167
- describe('with custom context', () => {
168
- it('should update as queries start and stop fetching', async () => {
169
- const context = React.createContext<QueryClient | undefined>(undefined)
170
-
171
- const queryCache = new QueryCache()
172
- const queryClient = createQueryClient({ queryCache })
173
- const key = queryKey()
174
-
175
- function Page() {
176
- const [ready, setReady] = React.useState(false)
177
-
178
- const isFetching = useIsFetching(undefined, { context: context })
179
-
180
- useQuery(
181
- key,
182
- async () => {
183
- await sleep(50)
184
- return 'test'
185
- },
186
- {
187
- enabled: ready,
188
- context,
189
- },
190
- )
191
-
192
- return (
193
- <div>
194
- <div>isFetching: {isFetching}</div>
195
- <button onClick={() => setReady(true)}>setReady</button>
196
- </div>
197
- )
198
- }
175
+ it('should show the correct fetching state when mounted after a query', async () => {
176
+ const queryClient = createQueryClient()
177
+ const key = queryKey()
199
178
 
200
- const { findByText, getByRole } = renderWithClient(
201
- queryClient,
202
- <Page />,
203
- {
204
- context,
179
+ function Page() {
180
+ useQuery({
181
+ queryKey: key,
182
+ queryFn: async () => {
183
+ await sleep(10)
184
+ return 'test'
205
185
  },
206
- )
207
-
208
- await findByText('isFetching: 0')
209
- fireEvent.click(getByRole('button', { name: /setReady/i }))
210
- await findByText('isFetching: 1')
211
- await findByText('isFetching: 0')
212
- })
213
-
214
- it('should throw if the context is not passed to useIsFetching', async () => {
215
- const context = React.createContext<QueryClient | undefined>(undefined)
216
-
217
- const queryCache = new QueryCache()
218
- const queryClient = createQueryClient({ queryCache })
219
- const key = queryKey()
220
-
221
- function Page() {
222
- const isFetching = useIsFetching()
223
-
224
- useQuery(key, async () => 'test', {
225
- enabled: true,
226
- context,
227
- useErrorBoundary: true,
228
- })
186
+ })
229
187
 
230
- return (
231
- <div>
232
- <div>isFetching: {isFetching}</div>
233
- </div>
234
- )
235
- }
188
+ const isFetching = useIsFetching()
236
189
 
237
- const rendered = renderWithClient(
238
- queryClient,
239
- <ErrorBoundary fallbackRender={() => <div>error boundary</div>}>
240
- <Page />
241
- </ErrorBoundary>,
242
- {
243
- context,
244
- },
190
+ return (
191
+ <div>
192
+ <div>isFetching: {isFetching}</div>
193
+ </div>
245
194
  )
195
+ }
246
196
 
247
- await waitFor(() => rendered.getByText('error boundary'))
248
- })
197
+ const rendered = renderWithClient(queryClient, <Page />)
198
+
199
+ await rendered.findByText('isFetching: 1')
200
+ await rendered.findByText('isFetching: 0')
249
201
  })
250
202
 
251
- it('should show the correct fetching state when mounted after a query', async () => {
203
+ it('should use provided custom queryClient', async () => {
252
204
  const queryClient = createQueryClient()
253
205
  const key = queryKey()
254
206
 
255
207
  function Page() {
256
- useQuery(key, async () => {
257
- await sleep(10)
258
- return 'test'
259
- })
208
+ useQuery(
209
+ {
210
+ queryKey: key,
211
+ queryFn: async () => {
212
+ await sleep(10)
213
+ return 'test'
214
+ },
215
+ },
216
+ queryClient,
217
+ )
260
218
 
261
- const isFetching = useIsFetching()
219
+ const isFetching = useIsFetching({}, queryClient)
262
220
 
263
221
  return (
264
222
  <div>
@@ -267,9 +225,8 @@ describe('useIsFetching', () => {
267
225
  )
268
226
  }
269
227
 
270
- const rendered = renderWithClient(queryClient, <Page />)
228
+ const rendered = render(<Page></Page>)
271
229
 
272
- await rendered.findByText('isFetching: 1')
273
- await rendered.findByText('isFetching: 0')
230
+ await waitFor(() => rendered.getByText('isFetching: 1'))
274
231
  })
275
232
  })