@trpc/react-query 10.6.0 → 10.8.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.
- package/dist/{createHooksInternal-10b1b7ef.mjs → createHooksInternal-9c1f8ad9.mjs} +25 -11
- package/dist/{createHooksInternal-860b8183.js → createHooksInternal-d8e5577b.js} +26 -9
- package/dist/createTRPCReact.d.ts +30 -9
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/{getArrayQueryKey-671d083c.js → getArrayQueryKey-4bdb5cc2.js} +6 -1
- package/dist/{getArrayQueryKey-30a7f2f6.mjs → getArrayQueryKey-86134f8b.mjs} +6 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/internals/context.d.ts +35 -23
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getArrayQueryKey.d.ts +9 -5
- package/dist/internals/getArrayQueryKey.d.ts.map +1 -1
- package/dist/internals/getClientArgs.d.ts +2 -0
- package/dist/internals/getClientArgs.d.ts.map +1 -0
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/useHookResult.d.ts +10 -0
- package/dist/internals/useHookResult.d.ts.map +1 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +19 -116
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +61 -0
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +1 -0
- package/dist/shared/hooks/types.d.ts +78 -0
- package/dist/shared/hooks/types.d.ts.map +1 -0
- package/dist/shared/index.d.ts +12 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +5 -2
- package/dist/shared/index.mjs +2 -2
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +6 -5
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/ssg/index.js +1 -1
- package/dist/ssg/index.mjs +1 -1
- package/dist/ssg/ssgProxy.d.ts +3 -3
- package/dist/ssg/ssgProxy.d.ts.map +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/createTRPCReact.tsx +79 -24
- package/src/internals/context.tsx +53 -52
- package/src/internals/getArrayQueryKey.test.ts +11 -0
- package/src/internals/getArrayQueryKey.ts +11 -2
- package/src/internals/getClientArgs.ts +7 -0
- package/src/internals/getQueryKey.ts +2 -1
- package/src/internals/useHookResult.ts +18 -0
- package/src/shared/hooks/createHooksInternal.tsx +71 -309
- package/src/shared/hooks/deprecated/createHooksInternal.tsx +628 -0
- package/src/shared/hooks/types.ts +151 -0
- package/src/shared/index.ts +17 -0
- package/src/shared/proxy/decorationProxy.ts +7 -0
- package/src/shared/proxy/utilsProxy.ts +7 -3
- package/src/ssg/ssgProxy.ts +8 -4
- package/src/utils/inferReactQueryProcedure.ts +1 -1
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import {
|
|
3
3
|
DehydratedState,
|
|
4
|
-
InfiniteQueryObserverSuccessResult,
|
|
5
4
|
QueryClient,
|
|
6
|
-
QueryObserverSuccessResult,
|
|
7
|
-
QueryOptions,
|
|
8
|
-
UseInfiniteQueryOptions,
|
|
9
|
-
UseInfiniteQueryResult,
|
|
10
|
-
UseMutationOptions,
|
|
11
|
-
UseMutationResult,
|
|
12
|
-
UseQueryOptions,
|
|
13
|
-
UseQueryResult,
|
|
14
5
|
useInfiniteQuery as __useInfiniteQuery,
|
|
15
6
|
useMutation as __useMutation,
|
|
16
7
|
useQueries as __useQueries,
|
|
@@ -18,195 +9,36 @@ import {
|
|
|
18
9
|
hashQueryKey,
|
|
19
10
|
useQueryClient,
|
|
20
11
|
} from '@tanstack/react-query';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from '@trpc/client';
|
|
28
|
-
import type {
|
|
29
|
-
AnyRouter,
|
|
30
|
-
ProcedureRecord,
|
|
31
|
-
inferHandlerInput,
|
|
32
|
-
inferProcedureClientError,
|
|
33
|
-
inferProcedureInput,
|
|
34
|
-
inferProcedureOutput,
|
|
35
|
-
inferSubscriptionOutput,
|
|
36
|
-
} from '@trpc/server';
|
|
37
|
-
import { inferObservableValue } from '@trpc/server/observable';
|
|
38
|
-
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
39
|
-
import React, {
|
|
40
|
-
ReactNode,
|
|
41
|
-
useCallback,
|
|
42
|
-
useEffect,
|
|
43
|
-
useMemo,
|
|
44
|
-
useRef,
|
|
45
|
-
useState,
|
|
46
|
-
} from 'react';
|
|
47
|
-
import {
|
|
48
|
-
SSRState,
|
|
49
|
-
TRPCContext,
|
|
50
|
-
TRPCContextProps,
|
|
51
|
-
TRPCContextState,
|
|
52
|
-
} from '../../internals/context';
|
|
12
|
+
import { TRPCClientErrorLike, createTRPCClient } from '@trpc/client';
|
|
13
|
+
import type { AnyRouter } from '@trpc/server';
|
|
14
|
+
import { Observable } from '@trpc/server/observable';
|
|
15
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { SSRState, TRPCContext } from '../../internals/context';
|
|
17
|
+
import { TRPCContextState } from '../../internals/context';
|
|
53
18
|
import { QueryType, getArrayQueryKey } from '../../internals/getArrayQueryKey';
|
|
19
|
+
import { getClientArgs } from '../../internals/getClientArgs';
|
|
20
|
+
import { useHookResult } from '../../internals/useHookResult';
|
|
54
21
|
import { TRPCUseQueries } from '../../internals/useQueries';
|
|
55
22
|
import { createUseQueriesProxy } from '../proxy/useQueriesProxy';
|
|
56
23
|
import { CreateTRPCReactOptions, UseMutationOverride } from '../types';
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Opt out or into aborting request on unmount
|
|
72
|
-
*/
|
|
73
|
-
abortOnUnmount?: boolean;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface TRPCUseQueryBaseOptions {
|
|
77
|
-
/**
|
|
78
|
-
* tRPC-related options
|
|
79
|
-
*/
|
|
80
|
-
trpc?: TRPCReactRequestOptions;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export type { TRPCContext, TRPCContextState } from '../../internals/context';
|
|
84
|
-
|
|
85
|
-
export interface UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>
|
|
86
|
-
extends UseQueryOptions<TOutput, TError, TData, [TPath, TInput]>,
|
|
87
|
-
TRPCUseQueryBaseOptions {}
|
|
88
|
-
|
|
89
|
-
export interface TRPCQueryOptions<TPath, TInput, TData, TError>
|
|
90
|
-
extends QueryOptions<TData, TError, TData, [TPath, TInput]>,
|
|
91
|
-
TRPCUseQueryBaseOptions {}
|
|
92
|
-
|
|
93
|
-
export interface UseTRPCInfiniteQueryOptions<TPath, TInput, TOutput, TError>
|
|
94
|
-
extends UseInfiniteQueryOptions<
|
|
95
|
-
TOutput,
|
|
96
|
-
TError,
|
|
97
|
-
TOutput,
|
|
98
|
-
TOutput,
|
|
99
|
-
[TPath, TInput]
|
|
100
|
-
>,
|
|
101
|
-
TRPCUseQueryBaseOptions {}
|
|
102
|
-
|
|
103
|
-
export interface UseTRPCMutationOptions<
|
|
104
|
-
TInput,
|
|
105
|
-
TError,
|
|
106
|
-
TOutput,
|
|
107
|
-
TContext = unknown,
|
|
108
|
-
> extends UseMutationOptions<TOutput, TError, TInput, TContext>,
|
|
109
|
-
TRPCUseQueryBaseOptions {}
|
|
110
|
-
|
|
111
|
-
export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
|
112
|
-
enabled?: boolean;
|
|
113
|
-
onStarted?: () => void;
|
|
114
|
-
onData: (data: TOutput) => void;
|
|
115
|
-
onError?: (err: TError) => void;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function getClientArgs<TPathAndInput extends unknown[], TOptions>(
|
|
119
|
-
pathAndInput: TPathAndInput,
|
|
120
|
-
opts: TOptions,
|
|
121
|
-
) {
|
|
122
|
-
const [path, input] = pathAndInput;
|
|
123
|
-
return [path, input, (opts as any)?.trpc] as const;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
type inferInfiniteQueryNames<TObj extends ProcedureRecord> = {
|
|
127
|
-
[TPath in keyof TObj]: inferProcedureInput<TObj[TPath]> extends {
|
|
128
|
-
cursor?: any;
|
|
129
|
-
}
|
|
130
|
-
? TPath
|
|
131
|
-
: never;
|
|
132
|
-
}[keyof TObj];
|
|
133
|
-
|
|
134
|
-
type inferProcedures<TObj extends ProcedureRecord> = {
|
|
135
|
-
[TPath in keyof TObj]: {
|
|
136
|
-
input: inferProcedureInput<TObj[TPath]>;
|
|
137
|
-
output: inferTransformedProcedureOutput<TObj[TPath]>;
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext>
|
|
142
|
-
extends TRPCContextProps<TRouter, TSSRContext> {
|
|
143
|
-
children: ReactNode;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (
|
|
147
|
-
props: TRPCProviderProps<TRouter, TSSRContext>,
|
|
148
|
-
) => JSX.Element;
|
|
149
|
-
|
|
150
|
-
export type UseDehydratedState<TRouter extends AnyRouter> = (
|
|
151
|
-
client: TRPCClient<TRouter>,
|
|
152
|
-
trpcState: DehydratedState | undefined,
|
|
153
|
-
) => DehydratedState | undefined;
|
|
154
|
-
|
|
155
|
-
export type CreateClient<TRouter extends AnyRouter> = (
|
|
156
|
-
opts: CreateTRPCClientOptions<TRouter>,
|
|
157
|
-
) => TRPCClient<TRouter>;
|
|
158
|
-
|
|
159
|
-
interface TRPCHookResult {
|
|
160
|
-
trpc: {
|
|
161
|
-
path: string;
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @internal
|
|
167
|
-
*/
|
|
168
|
-
export type UseTRPCQueryResult<TData, TError> = UseQueryResult<TData, TError> &
|
|
169
|
-
TRPCHookResult;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
export type UseTRPCQuerySuccessResult<TData, TError> =
|
|
175
|
-
QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
|
|
176
|
-
/**
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
export type UseTRPCInfiniteQueryResult<TData, TError> = UseInfiniteQueryResult<
|
|
180
|
-
TData,
|
|
181
|
-
TError
|
|
182
|
-
> &
|
|
183
|
-
TRPCHookResult;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* @internal
|
|
187
|
-
*/
|
|
188
|
-
export type UseTRPCInfiniteQuerySuccessResult<TData, TError> =
|
|
189
|
-
InfiniteQueryObserverSuccessResult<TData, TError> & TRPCHookResult;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @internal
|
|
193
|
-
*/
|
|
194
|
-
export type UseTRPCMutationResult<TData, TError, TVariables, TContext> =
|
|
195
|
-
UseMutationResult<TData, TError, TVariables, TContext> & TRPCHookResult;
|
|
24
|
+
import {
|
|
25
|
+
CreateClient,
|
|
26
|
+
TRPCProvider,
|
|
27
|
+
TRPCQueryOptions,
|
|
28
|
+
UseDehydratedState,
|
|
29
|
+
UseTRPCInfiniteQueryOptions,
|
|
30
|
+
UseTRPCInfiniteQueryResult,
|
|
31
|
+
UseTRPCMutationOptions,
|
|
32
|
+
UseTRPCMutationResult,
|
|
33
|
+
UseTRPCQueryOptions,
|
|
34
|
+
UseTRPCQueryResult,
|
|
35
|
+
UseTRPCSubscriptionOptions,
|
|
36
|
+
} from './types';
|
|
196
37
|
|
|
197
38
|
/**
|
|
198
|
-
* Makes a stable reference of the `trpc` prop
|
|
199
|
-
*/
|
|
200
|
-
function useHookResult(value: TRPCHookResult['trpc']): TRPCHookResult['trpc'] {
|
|
201
|
-
const ref = useRef(value);
|
|
202
|
-
ref.current.path = value.path;
|
|
203
|
-
return ref.current;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Create strongly typed react hooks
|
|
207
39
|
* @internal
|
|
208
40
|
*/
|
|
209
|
-
export function
|
|
41
|
+
export function createRootHooks<
|
|
210
42
|
TRouter extends AnyRouter,
|
|
211
43
|
TSSRContext = unknown,
|
|
212
44
|
>(config?: CreateTRPCReactOptions<TRouter>) {
|
|
@@ -214,15 +46,7 @@ export function createHooksInternal<
|
|
|
214
46
|
config?.unstable_overrides?.useMutation?.onSuccess ??
|
|
215
47
|
((options) => options.originalFn());
|
|
216
48
|
|
|
217
|
-
type TQueries = TRouter['_def']['queries'];
|
|
218
|
-
type TSubscriptions = TRouter['_def']['subscriptions'];
|
|
219
|
-
type TMutations = TRouter['_def']['mutations'];
|
|
220
|
-
|
|
221
49
|
type TError = TRPCClientErrorLike<TRouter>;
|
|
222
|
-
type TInfiniteQueryNames = inferInfiniteQueryNames<TQueries>;
|
|
223
|
-
|
|
224
|
-
type TQueryValues = inferProcedures<TQueries>;
|
|
225
|
-
type TMutationValues = inferProcedures<TMutations>;
|
|
226
50
|
|
|
227
51
|
type ProviderContext = TRPCContextState<TRouter, TSSRContext>;
|
|
228
52
|
|
|
@@ -424,20 +248,11 @@ export function createHooksInternal<
|
|
|
424
248
|
: opts;
|
|
425
249
|
}
|
|
426
250
|
|
|
427
|
-
function useQuery
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
>
|
|
432
|
-
pathAndInput: [path: TPath, ...args: inferHandlerInput<TQueries[TPath]>],
|
|
433
|
-
opts?: UseTRPCQueryOptions<
|
|
434
|
-
TPath,
|
|
435
|
-
TQueryValues[TPath]['input'],
|
|
436
|
-
TQueryFnData,
|
|
437
|
-
TData,
|
|
438
|
-
TError
|
|
439
|
-
>,
|
|
440
|
-
): UseTRPCQueryResult<TData, TError> {
|
|
251
|
+
function useQuery(
|
|
252
|
+
// FIXME path should be a tuple in next major
|
|
253
|
+
pathAndInput: [path: string, ...args: unknown[]],
|
|
254
|
+
opts?: UseTRPCQueryOptions<unknown, unknown, unknown, unknown, TError>,
|
|
255
|
+
): UseTRPCQueryResult<unknown, TError> {
|
|
441
256
|
const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } =
|
|
442
257
|
useContext();
|
|
443
258
|
|
|
@@ -472,7 +287,7 @@ export function createHooksInternal<
|
|
|
472
287
|
);
|
|
473
288
|
},
|
|
474
289
|
{ context: ReactQueryContext, ...ssrOpts },
|
|
475
|
-
) as UseTRPCQueryResult<
|
|
290
|
+
) as UseTRPCQueryResult<unknown, TError>;
|
|
476
291
|
hook.trpc = useHookResult({
|
|
477
292
|
path: pathAndInput[0],
|
|
478
293
|
});
|
|
@@ -480,23 +295,11 @@ export function createHooksInternal<
|
|
|
480
295
|
return hook;
|
|
481
296
|
}
|
|
482
297
|
|
|
483
|
-
function useMutation
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
opts?: UseTRPCMutationOptions<
|
|
489
|
-
TMutationValues[TPath]['input'],
|
|
490
|
-
TError,
|
|
491
|
-
TMutationValues[TPath]['output'],
|
|
492
|
-
TContext
|
|
493
|
-
>,
|
|
494
|
-
): UseTRPCMutationResult<
|
|
495
|
-
TMutationValues[TPath]['output'],
|
|
496
|
-
TError,
|
|
497
|
-
TMutationValues[TPath]['input'],
|
|
498
|
-
TContext
|
|
499
|
-
> {
|
|
298
|
+
function useMutation(
|
|
299
|
+
// FIXME: this should only be a tuple path in next major
|
|
300
|
+
path: string | [string],
|
|
301
|
+
opts?: UseTRPCMutationOptions<unknown, TError, unknown, unknown>,
|
|
302
|
+
): UseTRPCMutationResult<unknown, TError, unknown, unknown> {
|
|
500
303
|
const { client } = useContext();
|
|
501
304
|
const queryClient = useQueryClient({ context: ReactQueryContext });
|
|
502
305
|
|
|
@@ -521,12 +324,7 @@ export function createHooksInternal<
|
|
|
521
324
|
});
|
|
522
325
|
},
|
|
523
326
|
},
|
|
524
|
-
) as UseTRPCMutationResult<
|
|
525
|
-
TMutationValues[TPath]['output'],
|
|
526
|
-
TError,
|
|
527
|
-
TMutationValues[TPath]['input'],
|
|
528
|
-
TContext
|
|
529
|
-
>;
|
|
327
|
+
) as UseTRPCMutationResult<unknown, TError, unknown, unknown>;
|
|
530
328
|
|
|
531
329
|
hook.trpc = useHookResult({
|
|
532
330
|
path: Array.isArray(path) ? path[0] : path,
|
|
@@ -536,23 +334,13 @@ export function createHooksInternal<
|
|
|
536
334
|
}
|
|
537
335
|
|
|
538
336
|
/* istanbul ignore next */
|
|
539
|
-
|
|
540
|
-
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
|
|
541
|
-
* **Experimental.** API might change without major version bump
|
|
542
|
-
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠
|
|
543
|
-
*/
|
|
544
|
-
function useSubscription<
|
|
545
|
-
TPath extends keyof TSubscriptions & string,
|
|
546
|
-
TOutput extends inferSubscriptionOutput<TRouter, TPath>,
|
|
547
|
-
>(
|
|
337
|
+
function useSubscription(
|
|
548
338
|
pathAndInput: [
|
|
549
|
-
|
|
550
|
-
|
|
339
|
+
// FIXME: tuple me in next major
|
|
340
|
+
path: string,
|
|
341
|
+
...args: unknown[],
|
|
551
342
|
],
|
|
552
|
-
opts: UseTRPCSubscriptionOptions<
|
|
553
|
-
inferObservableValue<inferProcedureOutput<TSubscriptions[TPath]>>,
|
|
554
|
-
inferProcedureClientError<TSubscriptions[TPath]>
|
|
555
|
-
>,
|
|
343
|
+
opts: UseTRPCSubscriptionOptions<Observable<unknown, unknown>, TError>,
|
|
556
344
|
) {
|
|
557
345
|
const enabled = opts?.enabled ?? true;
|
|
558
346
|
const queryKey = hashQueryKey(pathAndInput);
|
|
@@ -564,28 +352,28 @@ export function createHooksInternal<
|
|
|
564
352
|
}
|
|
565
353
|
const [path, input] = pathAndInput;
|
|
566
354
|
let isStopped = false;
|
|
567
|
-
const subscription = client.subscription
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
355
|
+
const subscription = client.subscription(
|
|
356
|
+
path,
|
|
357
|
+
(input ?? undefined) as any,
|
|
358
|
+
{
|
|
359
|
+
onStarted: () => {
|
|
360
|
+
if (!isStopped) {
|
|
361
|
+
opts.onStarted?.();
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
onData: (data) => {
|
|
365
|
+
if (!isStopped) {
|
|
366
|
+
// FIXME this shouldn't be needed as both should be `unknown` in next major
|
|
367
|
+
opts.onData(data as any);
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
onError: (err) => {
|
|
371
|
+
if (!isStopped) {
|
|
372
|
+
opts.onError?.(err);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
587
375
|
},
|
|
588
|
-
|
|
376
|
+
);
|
|
589
377
|
return () => {
|
|
590
378
|
isStopped = true;
|
|
591
379
|
subscription.unsubscribe();
|
|
@@ -594,18 +382,14 @@ export function createHooksInternal<
|
|
|
594
382
|
}, [queryKey, enabled]);
|
|
595
383
|
}
|
|
596
384
|
|
|
597
|
-
function useInfiniteQuery
|
|
385
|
+
function useInfiniteQuery(
|
|
598
386
|
pathAndInput: [
|
|
599
|
-
|
|
600
|
-
|
|
387
|
+
// FIXME tuple in next major
|
|
388
|
+
path: string,
|
|
389
|
+
input: Record<any, unknown>,
|
|
601
390
|
],
|
|
602
|
-
opts?: UseTRPCInfiniteQueryOptions<
|
|
603
|
-
|
|
604
|
-
Omit<TQueryValues[TPath]['input'], 'cursor'>,
|
|
605
|
-
TQueryValues[TPath]['output'],
|
|
606
|
-
TError
|
|
607
|
-
>,
|
|
608
|
-
): UseTRPCInfiniteQueryResult<TQueryValues[TPath]['output'], TError> {
|
|
391
|
+
opts?: UseTRPCInfiniteQueryOptions<unknown, unknown, unknown, TError>,
|
|
392
|
+
): UseTRPCInfiniteQueryResult<unknown, TError> {
|
|
609
393
|
const [path, input] = pathAndInput;
|
|
610
394
|
const {
|
|
611
395
|
client,
|
|
@@ -650,12 +434,13 @@ export function createHooksInternal<
|
|
|
650
434
|
cursor: queryFunctionContext.pageParam,
|
|
651
435
|
};
|
|
652
436
|
|
|
437
|
+
// FIXME as any shouldn't be needed as client should be untyped too
|
|
653
438
|
return (client as any).query(
|
|
654
439
|
...getClientArgs([path, actualInput], actualOpts),
|
|
655
440
|
);
|
|
656
441
|
},
|
|
657
442
|
{ context: ReactQueryContext, ...ssrOpts },
|
|
658
|
-
) as UseTRPCInfiniteQueryResult<
|
|
443
|
+
) as UseTRPCInfiniteQueryResult<unknown, TError>;
|
|
659
444
|
|
|
660
445
|
hook.trpc = useHookResult({
|
|
661
446
|
path,
|
|
@@ -721,30 +506,7 @@ export function createHooksInternal<
|
|
|
721
506
|
}
|
|
722
507
|
|
|
723
508
|
/**
|
|
724
|
-
*
|
|
725
|
-
*
|
|
509
|
+
* @deprecated
|
|
510
|
+
* DELETE ME
|
|
726
511
|
*/
|
|
727
|
-
|
|
728
|
-
fn() {
|
|
729
|
-
return createHooksInternal<TRouter, TSSRContext>();
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
type returnTypeInferer<TType> = TType extends (
|
|
734
|
-
a: Record<string, string>,
|
|
735
|
-
) => infer U
|
|
736
|
-
? U
|
|
737
|
-
: never;
|
|
738
|
-
type fooType<TRouter extends AnyRouter, TSSRContext = unknown> = GnClass<
|
|
739
|
-
TRouter,
|
|
740
|
-
TSSRContext
|
|
741
|
-
>['fn'];
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Infer the type of a `createReactQueryHooks` function
|
|
745
|
-
* @internal
|
|
746
|
-
*/
|
|
747
|
-
export type CreateReactQueryHooks<
|
|
748
|
-
TRouter extends AnyRouter,
|
|
749
|
-
TSSRContext = unknown,
|
|
750
|
-
> = returnTypeInferer<fooType<TRouter, TSSRContext>>;
|
|
512
|
+
export * from './deprecated/createHooksInternal';
|