react-query-kit 3.1.1 → 3.1.3

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.
package/README.md CHANGED
@@ -48,6 +48,7 @@ English | [简体中文](./README-zh_CN.md)
48
48
  - [createMutation](#createmutation)
49
49
  - [router](#router)
50
50
  - [Middleware](#middleware)
51
+ - [TypeScript](#typescript)
51
52
  - [Type inference](#type-inference)
52
53
  - [FAQ](#faq)
53
54
  - [Migration](#migration)
@@ -86,12 +87,12 @@ If you still on React Query Kit v2? Check out the v2 docs here: https://github.c
86
87
  import { QueryClient, dehydrate } from '@tanstack/react-query'
87
88
  import { createQuery } from 'react-query-kit'
88
89
 
89
- type Response = { title: string; content: string }
90
+ type Data = { title: string; content: string }
90
91
  type Variables = { id: number }
91
92
 
92
93
  const usePost = createQuery({
93
94
  queryKey: ['posts'],
94
- fetcher: (variables: Variables): Promise<Response> => {
95
+ fetcher: (variables: Variables): Promise<Data> => {
95
96
  return fetch(`/posts/${variables.id}`).then(res => res.json())
96
97
  },
97
98
  // u can also pass middleware to cutomize this hook's behavior
@@ -142,7 +143,7 @@ const queries = useQueries({
142
143
  })
143
144
 
144
145
  // getQueryData
145
- queryClient.getQueryData(usePost.getKey(variables)) // Response
146
+ queryClient.getQueryData(usePost.getKey(variables)) // Data
146
147
 
147
148
  // setQueryData
148
149
  queryClient.setQueryData(usePost.getKey(variables), {...})
@@ -177,12 +178,12 @@ Expose Methods
177
178
  import { QueryClient, dehydrate } from '@tanstack/react-query'
178
179
  import { createInfiniteQuery } from 'react-query-kit'
179
180
 
180
- type Response = { projects: { id: string; name: string }[]; nextCursor: number }
181
+ type Data = { projects: { id: string; name: string }[]; nextCursor: number }
181
182
  type Variables = { active: boolean }
182
183
 
183
184
  const useProjects = createInfiniteQuery({
184
185
  queryKey: ['projects'],
185
- fetcher: (variables: Variables, { pageParam }): Promise<Response> => {
186
+ fetcher: (variables: Variables, { pageParam }): Promise<Data> => {
186
187
  return fetch(
187
188
  `/projects?cursor=${pageParam}?active=${variables.active}`
188
189
  ).then(res => res.json())
@@ -478,7 +479,7 @@ Middleware receive the hook and can execute logic before and after running it. I
478
479
  import { QueryClient } from '@tanstack/react-query'
479
480
  import { Middleware, MutationHook, QueryHook, getKey } from 'react-query-kit'
480
481
 
481
- const logger: Middleware<QueryHook<Response, Variables>> = useQueryNext => {
482
+ const logger: Middleware<QueryHook<Data, Variables>> = useQueryNext => {
482
483
  return options => {
483
484
  const log = useLogger()
484
485
  const fetcher = (variables, context) => {
@@ -493,7 +494,7 @@ const logger: Middleware<QueryHook<Response, Variables>> = useQueryNext => {
493
494
  }
494
495
  }
495
496
 
496
- const useUser = createQuery<Response, Variables>({
497
+ const useUser = createQuery<Data, Variables>({
497
498
  use: [logger],
498
499
  })
499
500
 
@@ -593,6 +594,45 @@ const useSomething = createQuery({
593
594
  useSomething({...}, anotherQueryClient)
594
595
  ```
595
596
 
597
+ ## TypeScript
598
+
599
+ By default, ReactQueryKit will also infer the types of `data` and `variables` from `fetcher`, so you can have the preferred types automatically.
600
+
601
+ ```ts
602
+ type Data = { title: string; content: string }
603
+ type Variables = { id: number }
604
+
605
+ const usePost = createQuery({
606
+ queryKey: ['posts'],
607
+ fetcher: (variables: Variables): Promise<Data> => {
608
+ return fetch(`/posts/${variables}`).then(res => res.json())
609
+ },
610
+ })
611
+
612
+ // `data` will be inferred as `Data | undefined`.
613
+ // `variables` will be inferred as `Variables`.
614
+ const { data } = usePost({ variables: { id: 1 } })
615
+ ```
616
+
617
+ You can also explicitly specify the types for `fetcher`‘s `variables` and `data`.
618
+
619
+ ```ts
620
+ type Data = { title: string; content: string }
621
+ type Variables = { id: number }
622
+
623
+ const usePost = createQuery<Data, Variables, Error>({
624
+ queryKey: ['posts'],
625
+ fetcher: variables => {
626
+ return fetch(`/posts/${variables}`).then(res => res.json())
627
+ },
628
+ })
629
+
630
+ // `data` will be inferred as `Data | undefined`.
631
+ // `error` will be inferred as `Error | null`
632
+ // `variables` will be inferred as `Variables`.
633
+ const { data, error } = usePost({ variables: { id: 1 } })
634
+ ```
635
+
596
636
  ## Type inference
597
637
 
598
638
  You can extract the TypeScript type of any custom hook with `inferData` or `inferVariables`
@@ -600,10 +640,10 @@ You can extract the TypeScript type of any custom hook with `inferData` or `infe
600
640
  ```ts
601
641
  import { inferData, inferFnData, inferError, inferVariables, inferOptions } from 'react-query-kit'
602
642
 
603
- const useProjects = createInfiniteQuery<Response, Variables, Error>(...)
643
+ const useProjects = createInfiniteQuery<Data, Variables, Error>(...)
604
644
 
605
- inferData<typeof useProjects> // InfiniteData<Response>
606
- inferFnData<typeof useProjects> // Response
645
+ inferData<typeof useProjects> // InfiniteData<Data>
646
+ inferFnData<typeof useProjects> // Data
607
647
  inferVariables<typeof useProjects> // Variables
608
648
  inferError<typeof useProjects> // Error
609
649
  inferOptions<typeof useProjects> // InfiniteQueryHookOptions<...>
@@ -101,18 +101,18 @@ export interface SuspenseInfiniteQueryHook<TFnData = unknown, TVariables = void,
101
101
  <TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(options?: SuspenseInfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): SuspenseInfiniteQueryHookResult<TData, TError>;
102
102
  }
103
103
  export interface CreateMutationOptions<TData = unknown, TVariables = void, TError = CompatibleError, TContext = unknown> extends UseMutationOptions<TData, TError, TVariables, TContext> {
104
- use?: Middleware<MutationHook<TData, TError, TVariables>>[];
104
+ use?: Middleware<MutationHook<TData, TVariables, TError>>[];
105
105
  }
106
106
  export interface MutationHookOptions<TData, TError, TVariables, TContext> extends Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationFn' | 'mutationKey'> {
107
- use?: Middleware<MutationHook<TData, TError, TVariables>>[];
107
+ use?: Middleware<MutationHook<TData, TVariables, TError>>[];
108
108
  }
109
109
  export type MutationHookResult<TData = unknown, TError = CompatibleError, TVariables = void, TContext = unknown> = UseMutationResult<TData, TError, TVariables, TContext>;
110
- export interface ExposeMutationMethods<TData = unknown, TVariables = void, TError = unknown, TDefaultContext = unknown> {
110
+ export interface ExposeMutationMethods<TData = unknown, TVariables = void, TError = CompatibleError, TDefaultContext = unknown> {
111
111
  getKey: () => MutationKey | undefined;
112
112
  getOptions: () => UseMutationOptions<TData, TError, TVariables, TDefaultContext>;
113
113
  mutationFn: MutationFunction<TData, TVariables>;
114
114
  }
115
- export interface MutationHook<TData = unknown, TVariables = void, TError = unknown, TDefaultContext = unknown> extends ExposeMutationMethods<TData, TVariables, TError, TDefaultContext> {
115
+ export interface MutationHook<TData = unknown, TVariables = void, TError = CompatibleError, TDefaultContext = unknown> extends ExposeMutationMethods<TData, TVariables, TError, TDefaultContext> {
116
116
  <TContext = TDefaultContext>(options?: MutationHookOptions<TData, TError, TVariables, TContext>, queryClient?: CompatibleWithV4<QueryClient, void>): MutationHookResult<TData, TError, TVariables, TContext>;
117
117
  }
118
118
  export type inferVariables<T> = T extends {
@@ -126,7 +126,7 @@ export type inferFnData<T> = T extends {
126
126
  } ? TFnData : T extends ExposeMutationMethods<infer TFnData, any, any, any> ? TFnData : never;
127
127
  export type inferError<T> = T extends ExposeMethods<any, any, infer TError> ? TError : T extends ExposeMethods<any, any, infer TError, any> ? TError : T extends ExposeMutationMethods<any, any, infer TError, any> ? TError : never;
128
128
  export type inferOptions<T> = T extends QueryHook<infer TFnData, infer TVariables, infer TError> ? QueryHookOptions<TFnData, TError, TFnData, TVariables> : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError> ? SuspenseQueryHookOptions<TFnData, TError, TFnData, TVariables> : T extends InfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? InfiniteQueryHookOptions<TFnData, TError, CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>, TVariables, TPageParam> : T extends SuspenseInfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? SuspenseInfiniteQueryHookOptions<TFnData, TError, CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>, TVariables, TPageParam> : T extends MutationHook<infer TFnData, infer TVariables, infer TError> ? MutationHookOptions<TFnData, TError, TVariables, unknown> : never;
129
- export type inferCreateOptions<T> = T extends QueryHook<infer TFnData, infer TVariables, infer TError> ? CreateQueryOptions<TFnData, TVariables, TError> : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError> ? CreateSuspenseQueryOptions<TFnData, TVariables, TError> : T extends InfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends SuspenseInfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateSuspenseInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends MutationHook<infer TFnData, infer TVariables, infer TError, infer TContext> ? CreateMutationOptions<TFnData, TError, TVariables, TContext> : never;
129
+ export type inferCreateOptions<T> = T extends QueryHook<infer TFnData, infer TVariables, infer TError> ? CreateQueryOptions<TFnData, TVariables, TError> : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError> ? CreateSuspenseQueryOptions<TFnData, TVariables, TError> : T extends InfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends SuspenseInfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateSuspenseInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends MutationHook<infer TFnData, infer TVariables, infer TError, infer TContext> ? CreateMutationOptions<TFnData, TVariables, TError, TContext> : never;
130
130
  export type RouterQueryOptions<TFnData, TVariables = void, TError = CompatibleError> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>;
131
131
  export type RouterQuery<TFnData, TVariables = void, TError = CompatibleError> = RouterQueryOptions<TFnData, TVariables, TError> & {
132
132
  _type: `q`;
@@ -154,7 +154,7 @@ export interface RouterConfig {
154
154
  [k: string]: RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | RouterConfig;
155
155
  }
156
156
  export type CreateRouter<TConfig extends RouterConfig> = {
157
- [K in keyof TConfig]: TConfig[K] extends RouterMutation<infer TFnData, infer TVariables, infer TError, infer TContext> ? ResolvedRouterMutation<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TContext> : TConfig[K] extends RouterInfiniteQuery<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? ResolvedRouterInfiniteQuery<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>> : TConfig[K] extends Omit<RouterQuery<infer TFnData, infer TVariables, infer TError>, 'queryKey'> ? ResolvedRouterQuery<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>> : TConfig[K] extends RouterConfig ? CreateRouter<TConfig[K]> : never;
157
+ [K in keyof TConfig]: TConfig[K] extends RouterMutation<infer TFnData, infer TVariables, infer TError, infer TContext> ? ResolvedRouterMutation<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TContext> : TConfig[K] extends RouterInfiniteQuery<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? ResolvedRouterInfiniteQuery<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>> : TConfig[K] extends RouterQuery<infer TFnData, infer TVariables, infer TError> ? ResolvedRouterQuery<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>> : TConfig[K] extends RouterConfig ? CreateRouter<TConfig[K]> : never;
158
158
  } & {
159
159
  getKey: () => string[];
160
160
  };
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"fd7f-1","name":"utils.ts"},{"uid":"fd7f-3","name":"createBaseQuery.ts"},{"uid":"fd7f-5","name":"createQuery.ts"},{"uid":"fd7f-7","name":"createSuspenseQuery.ts"},{"uid":"fd7f-9","name":"createInfiniteQuery.ts"},{"uid":"fd7f-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"fd7f-13","name":"createMutation.ts"},{"uid":"fd7f-15","name":"router.ts"},{"uid":"fd7f-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"fd7f-1":{"renderedLength":894,"gzipLength":449,"brotliLength":0,"mainUid":"fd7f-0"},"fd7f-3":{"renderedLength":1162,"gzipLength":397,"brotliLength":0,"mainUid":"fd7f-2"},"fd7f-5":{"renderedLength":91,"gzipLength":87,"brotliLength":0,"mainUid":"fd7f-4"},"fd7f-7":{"renderedLength":179,"gzipLength":118,"brotliLength":0,"mainUid":"fd7f-6"},"fd7f-9":{"renderedLength":107,"gzipLength":97,"brotliLength":0,"mainUid":"fd7f-8"},"fd7f-11":{"renderedLength":203,"gzipLength":128,"brotliLength":0,"mainUid":"fd7f-10"},"fd7f-13":{"renderedLength":271,"gzipLength":168,"brotliLength":0,"mainUid":"fd7f-12"},"fd7f-15":{"renderedLength":1152,"gzipLength":385,"brotliLength":0,"mainUid":"fd7f-14"},"fd7f-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"fd7f-16"}},"nodeMetas":{"fd7f-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"fd7f-1"},"imported":[{"uid":"fd7f-19"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-4"},{"uid":"fd7f-6"},{"uid":"fd7f-8"},{"uid":"fd7f-10"},{"uid":"fd7f-12"},{"uid":"fd7f-2"}]},"fd7f-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"fd7f-3"},"imported":[{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-4"},{"uid":"fd7f-6"},{"uid":"fd7f-8"},{"uid":"fd7f-10"}]},"fd7f-4":{"id":"/src/createQuery.ts","moduleParts":{"zip.esm.js":"fd7f-5"},"imported":[{"uid":"fd7f-2"},{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-14"}]},"fd7f-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"fd7f-7"},"imported":[{"uid":"fd7f-2"},{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-14"}]},"fd7f-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"fd7f-9"},"imported":[{"uid":"fd7f-2"},{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-14"}]},"fd7f-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"fd7f-11"},"imported":[{"uid":"fd7f-2"},{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-14"}]},"fd7f-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"fd7f-13"},"imported":[{"uid":"fd7f-0"}],"importedBy":[{"uid":"fd7f-16"},{"uid":"fd7f-14"}]},"fd7f-14":{"id":"/src/router.ts","moduleParts":{"zip.esm.js":"fd7f-15"},"imported":[{"uid":"fd7f-8"},{"uid":"fd7f-12"},{"uid":"fd7f-4"},{"uid":"fd7f-10"},{"uid":"fd7f-6"}],"importedBy":[{"uid":"fd7f-16"}]},"fd7f-16":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"fd7f-17"},"imported":[{"uid":"fd7f-4"},{"uid":"fd7f-6"},{"uid":"fd7f-8"},{"uid":"fd7f-10"},{"uid":"fd7f-12"},{"uid":"fd7f-18"},{"uid":"fd7f-14"},{"uid":"fd7f-0"}],"importedBy":[],"isEntry":true},"fd7f-18":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"fd7f-16"}]},"fd7f-19":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"fd7f-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"5252-1","name":"utils.ts"},{"uid":"5252-3","name":"createBaseQuery.ts"},{"uid":"5252-5","name":"createQuery.ts"},{"uid":"5252-7","name":"createSuspenseQuery.ts"},{"uid":"5252-9","name":"createInfiniteQuery.ts"},{"uid":"5252-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"5252-13","name":"createMutation.ts"},{"uid":"5252-15","name":"router.ts"},{"uid":"5252-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"5252-1":{"renderedLength":894,"gzipLength":449,"brotliLength":0,"mainUid":"5252-0"},"5252-3":{"renderedLength":1162,"gzipLength":397,"brotliLength":0,"mainUid":"5252-2"},"5252-5":{"renderedLength":91,"gzipLength":87,"brotliLength":0,"mainUid":"5252-4"},"5252-7":{"renderedLength":179,"gzipLength":118,"brotliLength":0,"mainUid":"5252-6"},"5252-9":{"renderedLength":107,"gzipLength":97,"brotliLength":0,"mainUid":"5252-8"},"5252-11":{"renderedLength":203,"gzipLength":128,"brotliLength":0,"mainUid":"5252-10"},"5252-13":{"renderedLength":271,"gzipLength":168,"brotliLength":0,"mainUid":"5252-12"},"5252-15":{"renderedLength":1152,"gzipLength":385,"brotliLength":0,"mainUid":"5252-14"},"5252-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"5252-16"}},"nodeMetas":{"5252-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"5252-1"},"imported":[{"uid":"5252-19"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-4"},{"uid":"5252-6"},{"uid":"5252-8"},{"uid":"5252-10"},{"uid":"5252-12"},{"uid":"5252-2"}]},"5252-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"5252-3"},"imported":[{"uid":"5252-0"}],"importedBy":[{"uid":"5252-4"},{"uid":"5252-6"},{"uid":"5252-8"},{"uid":"5252-10"}]},"5252-4":{"id":"/src/createQuery.ts","moduleParts":{"zip.esm.js":"5252-5"},"imported":[{"uid":"5252-2"},{"uid":"5252-0"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-14"}]},"5252-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"5252-7"},"imported":[{"uid":"5252-2"},{"uid":"5252-0"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-14"}]},"5252-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"5252-9"},"imported":[{"uid":"5252-2"},{"uid":"5252-0"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-14"}]},"5252-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"5252-11"},"imported":[{"uid":"5252-2"},{"uid":"5252-0"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-14"}]},"5252-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"5252-13"},"imported":[{"uid":"5252-0"}],"importedBy":[{"uid":"5252-16"},{"uid":"5252-14"}]},"5252-14":{"id":"/src/router.ts","moduleParts":{"zip.esm.js":"5252-15"},"imported":[{"uid":"5252-8"},{"uid":"5252-12"},{"uid":"5252-4"},{"uid":"5252-10"},{"uid":"5252-6"}],"importedBy":[{"uid":"5252-16"}]},"5252-16":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"5252-17"},"imported":[{"uid":"5252-4"},{"uid":"5252-6"},{"uid":"5252-8"},{"uid":"5252-10"},{"uid":"5252-12"},{"uid":"5252-18"},{"uid":"5252-14"},{"uid":"5252-0"}],"importedBy":[],"isEntry":true},"5252-18":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"5252-16"}]},"5252-19":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"5252-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
package/build/stats.json CHANGED
@@ -10,39 +10,39 @@
10
10
  "name": "src",
11
11
  "children": [
12
12
  {
13
- "uid": "fd7f-21",
13
+ "uid": "5252-21",
14
14
  "name": "utils.ts"
15
15
  },
16
16
  {
17
- "uid": "fd7f-23",
17
+ "uid": "5252-23",
18
18
  "name": "createBaseQuery.ts"
19
19
  },
20
20
  {
21
- "uid": "fd7f-25",
21
+ "uid": "5252-25",
22
22
  "name": "createQuery.ts"
23
23
  },
24
24
  {
25
- "uid": "fd7f-27",
25
+ "uid": "5252-27",
26
26
  "name": "createSuspenseQuery.ts"
27
27
  },
28
28
  {
29
- "uid": "fd7f-29",
29
+ "uid": "5252-29",
30
30
  "name": "createInfiniteQuery.ts"
31
31
  },
32
32
  {
33
- "uid": "fd7f-31",
33
+ "uid": "5252-31",
34
34
  "name": "createSuspenseInfiniteQuery.ts"
35
35
  },
36
36
  {
37
- "uid": "fd7f-33",
37
+ "uid": "5252-33",
38
38
  "name": "createMutation.ts"
39
39
  },
40
40
  {
41
- "uid": "fd7f-35",
41
+ "uid": "5252-35",
42
42
  "name": "router.ts"
43
43
  },
44
44
  {
45
- "uid": "fd7f-37",
45
+ "uid": "5252-37",
46
46
  "name": "index.ts"
47
47
  }
48
48
  ]
@@ -53,307 +53,307 @@
53
53
  "isRoot": true
54
54
  },
55
55
  "nodeParts": {
56
- "fd7f-21": {
56
+ "5252-21": {
57
57
  "renderedLength": 894,
58
58
  "gzipLength": 449,
59
59
  "brotliLength": 0,
60
- "mainUid": "fd7f-20"
60
+ "mainUid": "5252-20"
61
61
  },
62
- "fd7f-23": {
62
+ "5252-23": {
63
63
  "renderedLength": 1162,
64
64
  "gzipLength": 397,
65
65
  "brotliLength": 0,
66
- "mainUid": "fd7f-22"
66
+ "mainUid": "5252-22"
67
67
  },
68
- "fd7f-25": {
68
+ "5252-25": {
69
69
  "renderedLength": 91,
70
70
  "gzipLength": 87,
71
71
  "brotliLength": 0,
72
- "mainUid": "fd7f-24"
72
+ "mainUid": "5252-24"
73
73
  },
74
- "fd7f-27": {
74
+ "5252-27": {
75
75
  "renderedLength": 179,
76
76
  "gzipLength": 118,
77
77
  "brotliLength": 0,
78
- "mainUid": "fd7f-26"
78
+ "mainUid": "5252-26"
79
79
  },
80
- "fd7f-29": {
80
+ "5252-29": {
81
81
  "renderedLength": 107,
82
82
  "gzipLength": 97,
83
83
  "brotliLength": 0,
84
- "mainUid": "fd7f-28"
84
+ "mainUid": "5252-28"
85
85
  },
86
- "fd7f-31": {
86
+ "5252-31": {
87
87
  "renderedLength": 203,
88
88
  "gzipLength": 128,
89
89
  "brotliLength": 0,
90
- "mainUid": "fd7f-30"
90
+ "mainUid": "5252-30"
91
91
  },
92
- "fd7f-33": {
92
+ "5252-33": {
93
93
  "renderedLength": 271,
94
94
  "gzipLength": 168,
95
95
  "brotliLength": 0,
96
- "mainUid": "fd7f-32"
96
+ "mainUid": "5252-32"
97
97
  },
98
- "fd7f-35": {
98
+ "5252-35": {
99
99
  "renderedLength": 1152,
100
100
  "gzipLength": 385,
101
101
  "brotliLength": 0,
102
- "mainUid": "fd7f-34"
102
+ "mainUid": "5252-34"
103
103
  },
104
- "fd7f-37": {
104
+ "5252-37": {
105
105
  "renderedLength": 0,
106
106
  "gzipLength": 0,
107
107
  "brotliLength": 0,
108
- "mainUid": "fd7f-36"
108
+ "mainUid": "5252-36"
109
109
  }
110
110
  },
111
111
  "nodeMetas": {
112
- "fd7f-20": {
112
+ "5252-20": {
113
113
  "id": "/src/utils.ts",
114
114
  "moduleParts": {
115
- "zip.esm.js": "fd7f-21"
115
+ "zip.esm.js": "5252-21"
116
116
  },
117
117
  "imported": [
118
118
  {
119
- "uid": "fd7f-39"
119
+ "uid": "5252-39"
120
120
  }
121
121
  ],
122
122
  "importedBy": [
123
123
  {
124
- "uid": "fd7f-36"
124
+ "uid": "5252-36"
125
125
  },
126
126
  {
127
- "uid": "fd7f-24"
127
+ "uid": "5252-24"
128
128
  },
129
129
  {
130
- "uid": "fd7f-26"
130
+ "uid": "5252-26"
131
131
  },
132
132
  {
133
- "uid": "fd7f-28"
133
+ "uid": "5252-28"
134
134
  },
135
135
  {
136
- "uid": "fd7f-30"
136
+ "uid": "5252-30"
137
137
  },
138
138
  {
139
- "uid": "fd7f-32"
139
+ "uid": "5252-32"
140
140
  },
141
141
  {
142
- "uid": "fd7f-22"
142
+ "uid": "5252-22"
143
143
  }
144
144
  ]
145
145
  },
146
- "fd7f-22": {
146
+ "5252-22": {
147
147
  "id": "/src/createBaseQuery.ts",
148
148
  "moduleParts": {
149
- "zip.esm.js": "fd7f-23"
149
+ "zip.esm.js": "5252-23"
150
150
  },
151
151
  "imported": [
152
152
  {
153
- "uid": "fd7f-20"
153
+ "uid": "5252-20"
154
154
  }
155
155
  ],
156
156
  "importedBy": [
157
157
  {
158
- "uid": "fd7f-24"
158
+ "uid": "5252-24"
159
159
  },
160
160
  {
161
- "uid": "fd7f-26"
161
+ "uid": "5252-26"
162
162
  },
163
163
  {
164
- "uid": "fd7f-28"
164
+ "uid": "5252-28"
165
165
  },
166
166
  {
167
- "uid": "fd7f-30"
167
+ "uid": "5252-30"
168
168
  }
169
169
  ]
170
170
  },
171
- "fd7f-24": {
171
+ "5252-24": {
172
172
  "id": "/src/createQuery.ts",
173
173
  "moduleParts": {
174
- "zip.esm.js": "fd7f-25"
174
+ "zip.esm.js": "5252-25"
175
175
  },
176
176
  "imported": [
177
177
  {
178
- "uid": "fd7f-22"
178
+ "uid": "5252-22"
179
179
  },
180
180
  {
181
- "uid": "fd7f-20"
181
+ "uid": "5252-20"
182
182
  }
183
183
  ],
184
184
  "importedBy": [
185
185
  {
186
- "uid": "fd7f-36"
186
+ "uid": "5252-36"
187
187
  },
188
188
  {
189
- "uid": "fd7f-34"
189
+ "uid": "5252-34"
190
190
  }
191
191
  ]
192
192
  },
193
- "fd7f-26": {
193
+ "5252-26": {
194
194
  "id": "/src/createSuspenseQuery.ts",
195
195
  "moduleParts": {
196
- "zip.esm.js": "fd7f-27"
196
+ "zip.esm.js": "5252-27"
197
197
  },
198
198
  "imported": [
199
199
  {
200
- "uid": "fd7f-22"
200
+ "uid": "5252-22"
201
201
  },
202
202
  {
203
- "uid": "fd7f-20"
203
+ "uid": "5252-20"
204
204
  }
205
205
  ],
206
206
  "importedBy": [
207
207
  {
208
- "uid": "fd7f-36"
208
+ "uid": "5252-36"
209
209
  },
210
210
  {
211
- "uid": "fd7f-34"
211
+ "uid": "5252-34"
212
212
  }
213
213
  ]
214
214
  },
215
- "fd7f-28": {
215
+ "5252-28": {
216
216
  "id": "/src/createInfiniteQuery.ts",
217
217
  "moduleParts": {
218
- "zip.esm.js": "fd7f-29"
218
+ "zip.esm.js": "5252-29"
219
219
  },
220
220
  "imported": [
221
221
  {
222
- "uid": "fd7f-22"
222
+ "uid": "5252-22"
223
223
  },
224
224
  {
225
- "uid": "fd7f-20"
225
+ "uid": "5252-20"
226
226
  }
227
227
  ],
228
228
  "importedBy": [
229
229
  {
230
- "uid": "fd7f-36"
230
+ "uid": "5252-36"
231
231
  },
232
232
  {
233
- "uid": "fd7f-34"
233
+ "uid": "5252-34"
234
234
  }
235
235
  ]
236
236
  },
237
- "fd7f-30": {
237
+ "5252-30": {
238
238
  "id": "/src/createSuspenseInfiniteQuery.ts",
239
239
  "moduleParts": {
240
- "zip.esm.js": "fd7f-31"
240
+ "zip.esm.js": "5252-31"
241
241
  },
242
242
  "imported": [
243
243
  {
244
- "uid": "fd7f-22"
244
+ "uid": "5252-22"
245
245
  },
246
246
  {
247
- "uid": "fd7f-20"
247
+ "uid": "5252-20"
248
248
  }
249
249
  ],
250
250
  "importedBy": [
251
251
  {
252
- "uid": "fd7f-36"
252
+ "uid": "5252-36"
253
253
  },
254
254
  {
255
- "uid": "fd7f-34"
255
+ "uid": "5252-34"
256
256
  }
257
257
  ]
258
258
  },
259
- "fd7f-32": {
259
+ "5252-32": {
260
260
  "id": "/src/createMutation.ts",
261
261
  "moduleParts": {
262
- "zip.esm.js": "fd7f-33"
262
+ "zip.esm.js": "5252-33"
263
263
  },
264
264
  "imported": [
265
265
  {
266
- "uid": "fd7f-20"
266
+ "uid": "5252-20"
267
267
  }
268
268
  ],
269
269
  "importedBy": [
270
270
  {
271
- "uid": "fd7f-36"
271
+ "uid": "5252-36"
272
272
  },
273
273
  {
274
- "uid": "fd7f-34"
274
+ "uid": "5252-34"
275
275
  }
276
276
  ]
277
277
  },
278
- "fd7f-34": {
278
+ "5252-34": {
279
279
  "id": "/src/router.ts",
280
280
  "moduleParts": {
281
- "zip.esm.js": "fd7f-35"
281
+ "zip.esm.js": "5252-35"
282
282
  },
283
283
  "imported": [
284
284
  {
285
- "uid": "fd7f-28"
285
+ "uid": "5252-28"
286
286
  },
287
287
  {
288
- "uid": "fd7f-32"
288
+ "uid": "5252-32"
289
289
  },
290
290
  {
291
- "uid": "fd7f-24"
291
+ "uid": "5252-24"
292
292
  },
293
293
  {
294
- "uid": "fd7f-30"
294
+ "uid": "5252-30"
295
295
  },
296
296
  {
297
- "uid": "fd7f-26"
297
+ "uid": "5252-26"
298
298
  }
299
299
  ],
300
300
  "importedBy": [
301
301
  {
302
- "uid": "fd7f-36"
302
+ "uid": "5252-36"
303
303
  }
304
304
  ]
305
305
  },
306
- "fd7f-36": {
306
+ "5252-36": {
307
307
  "id": "/src/index.ts",
308
308
  "moduleParts": {
309
- "zip.esm.js": "fd7f-37"
309
+ "zip.esm.js": "5252-37"
310
310
  },
311
311
  "imported": [
312
312
  {
313
- "uid": "fd7f-24"
313
+ "uid": "5252-24"
314
314
  },
315
315
  {
316
- "uid": "fd7f-26"
316
+ "uid": "5252-26"
317
317
  },
318
318
  {
319
- "uid": "fd7f-28"
319
+ "uid": "5252-28"
320
320
  },
321
321
  {
322
- "uid": "fd7f-30"
322
+ "uid": "5252-30"
323
323
  },
324
324
  {
325
- "uid": "fd7f-32"
325
+ "uid": "5252-32"
326
326
  },
327
327
  {
328
- "uid": "fd7f-38"
328
+ "uid": "5252-38"
329
329
  },
330
330
  {
331
- "uid": "fd7f-34"
331
+ "uid": "5252-34"
332
332
  },
333
333
  {
334
- "uid": "fd7f-20"
334
+ "uid": "5252-20"
335
335
  }
336
336
  ],
337
337
  "importedBy": [],
338
338
  "isEntry": true
339
339
  },
340
- "fd7f-38": {
340
+ "5252-38": {
341
341
  "id": "/src/types.ts",
342
342
  "moduleParts": {},
343
343
  "imported": [],
344
344
  "importedBy": [
345
345
  {
346
- "uid": "fd7f-36"
346
+ "uid": "5252-36"
347
347
  }
348
348
  ]
349
349
  },
350
- "fd7f-39": {
350
+ "5252-39": {
351
351
  "id": "@tanstack/react-query",
352
352
  "moduleParts": {},
353
353
  "imported": [],
354
354
  "importedBy": [
355
355
  {
356
- "uid": "fd7f-20"
356
+ "uid": "5252-20"
357
357
  }
358
358
  ],
359
359
  "isExternal": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "🕊️ A toolkit for ReactQuery that make ReactQuery hooks more reusable and typesafe",
5
5
  "author": "liaoliao666",
6
6
  "repository": "liaoliao666/react-query-kit",
package/src/types.ts CHANGED
@@ -445,7 +445,7 @@ export interface CreateMutationOptions<
445
445
  TError = CompatibleError,
446
446
  TContext = unknown
447
447
  > extends UseMutationOptions<TData, TError, TVariables, TContext> {
448
- use?: Middleware<MutationHook<TData, TError, TVariables>>[]
448
+ use?: Middleware<MutationHook<TData, TVariables, TError>>[]
449
449
  }
450
450
 
451
451
  export interface MutationHookOptions<TData, TError, TVariables, TContext>
@@ -453,7 +453,7 @@ export interface MutationHookOptions<TData, TError, TVariables, TContext>
453
453
  UseMutationOptions<TData, TError, TVariables, TContext>,
454
454
  'mutationFn' | 'mutationKey'
455
455
  > {
456
- use?: Middleware<MutationHook<TData, TError, TVariables>>[]
456
+ use?: Middleware<MutationHook<TData, TVariables, TError>>[]
457
457
  }
458
458
 
459
459
  export type MutationHookResult<
@@ -466,7 +466,7 @@ export type MutationHookResult<
466
466
  export interface ExposeMutationMethods<
467
467
  TData = unknown,
468
468
  TVariables = void,
469
- TError = unknown,
469
+ TError = CompatibleError,
470
470
  TDefaultContext = unknown
471
471
  > {
472
472
  getKey: () => MutationKey | undefined
@@ -482,7 +482,7 @@ export interface ExposeMutationMethods<
482
482
  export interface MutationHook<
483
483
  TData = unknown,
484
484
  TVariables = void,
485
- TError = unknown,
485
+ TError = CompatibleError,
486
486
  TDefaultContext = unknown
487
487
  > extends ExposeMutationMethods<TData, TVariables, TError, TDefaultContext> {
488
488
  <TContext = TDefaultContext>(
@@ -593,7 +593,7 @@ export type inferCreateOptions<T> = T extends QueryHook<
593
593
  infer TError,
594
594
  infer TContext
595
595
  >
596
- ? CreateMutationOptions<TFnData, TError, TVariables, TContext>
596
+ ? CreateMutationOptions<TFnData, TVariables, TError, TContext>
597
597
  : never
598
598
 
599
599
  // router
@@ -731,9 +731,10 @@ export type CreateRouter<TConfig extends RouterConfig> = {
731
731
  DefaultTo<TError, CompatibleError>,
732
732
  DefaultTo<TPageParam, number>
733
733
  >
734
- : TConfig[K] extends Omit<
735
- RouterQuery<infer TFnData, infer TVariables, infer TError>,
736
- 'queryKey'
734
+ : TConfig[K] extends RouterQuery<
735
+ infer TFnData,
736
+ infer TVariables,
737
+ infer TError
737
738
  >
738
739
  ? ResolvedRouterQuery<
739
740
  TFnData,