|
16 | 16 | <a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/v/react-query-kit" alt="Latest published version" target="\_parent"></a> |
17 | 17 | <a href="https://unpkg.com/browse/react-query-kit@latest/build/umd/index.production.js" rel="nofollow"><img src="https://img.badgesize.io/https:/unpkg.com/react-query-kit@latest/build/umd/index.production.js?label=gzip%20size&compression=gzip" alt="gzip size"></a> |
18 | 18 | <a href="https://github.com/liaoliao666/react-query-kit"><img src="https://badgen.net/npm/types/react-query-kit" alt="Types included" target="\_parent"></a> |
19 | | - <a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/license/react-query-kit" alt="License" target="\_parent"></a> |
| 19 | + <a href="https://github.com/liaoliao666/react-query-kit/blob/main/LICENSE"><img src="https://badgen.net/npm/license/react-query-kit" alt="License" target="\_parent"></a> |
20 | 20 | <a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/dt/react-query-kit" alt="Number of downloads" target="\_parent"></a> |
21 | 21 | <a href="https://github.com/liaoliao666/react-query-kit"><img src="https://img.shields.io/github/stars/liaoliao666/react-query-kit.svg?style=social&label=Star" alt="GitHub Stars" target="\_parent"></a> |
22 | 22 | </p> |
@@ -384,17 +384,20 @@ import { Middleware, MutationHook, QueryHook, getKey } from 'react-query-kit' |
384 | 384 | const myMiddleware: Middleware< |
385 | 385 | QueryHook<Response, Variables> |
386 | 386 | > = useQueryNext => { |
387 | | - return options => { |
| 387 | + return (options, queryClient) => { |
388 | 388 | const { userId } = useAuth() |
389 | | - const client = useQueryClient() |
| 389 | + const client = useQueryClient(queryClient) |
390 | 390 | const variables = options.variables ?? { id: userId } |
391 | 391 | const hasData = () => !!client.getQueryData(useUser.getKey(variables)) |
392 | 392 |
|
393 | | - return useQueryNext({ |
394 | | - ...options, |
395 | | - variables, |
396 | | - enabled: options.enabled ?? !hasData(), |
397 | | - }) |
| 393 | + return useQueryNext( |
| 394 | + { |
| 395 | + ...options, |
| 396 | + variables, |
| 397 | + enabled: options.enabled ?? !hasData(), |
| 398 | + }, |
| 399 | + queryClient |
| 400 | + ) |
398 | 401 | } |
399 | 402 | } |
400 | 403 |
|
@@ -482,13 +485,14 @@ exit a |
482 | 485 | You can extract the TypeScript type of any custom hook with `inferData` or `inferVariables` |
483 | 486 |
|
484 | 487 | ```ts |
485 | | -import { inferData, inferFnData, inferVariables, inferOptions } from 'react-query-kit' |
| 488 | +import { inferData, inferFnData, inferError, inferVariables, inferOptions } from 'react-query-kit' |
486 | 489 |
|
487 | | -const useProjects = createInfiniteQuery<Response, Variables>(...) |
| 490 | +const useProjects = createInfiniteQuery<Response, Variables, Error>(...) |
488 | 491 |
|
489 | 492 | inferData<typeof useProjects> // InfiniteData<Response> |
490 | 493 | inferFnData<typeof useProjects> // Response |
491 | 494 | inferVariables<typeof useProjects> // Variables |
| 495 | +inferError<typeof useProjects> // Error |
492 | 496 | inferOptions<typeof useProjects> // InfiniteQueryHookOptions<...> |
493 | 497 | ``` |
494 | 498 |
|
|
0 commit comments