@trpc/react-query 10.6.0 → 10.7.1-alpha-next-2023-08-07-23-17-43.62

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 (113) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +4 -5
  3. package/dist/createHooksInternal-2984dad9.js +396 -0
  4. package/dist/createHooksInternal-7f20c371.js +452 -0
  5. package/dist/createHooksInternal-a0ed7011.mjs +443 -0
  6. package/dist/createTRPCReact.d.ts +74 -50
  7. package/dist/createTRPCReact.d.ts.map +1 -1
  8. package/dist/index.d.ts +4 -4
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +5 -17
  11. package/dist/index.mjs +5 -16
  12. package/dist/internals/context.d.ts +109 -110
  13. package/dist/internals/context.d.ts.map +1 -1
  14. package/dist/internals/getClientArgs.d.ts +3 -0
  15. package/dist/internals/getClientArgs.d.ts.map +1 -0
  16. package/dist/internals/getQueryKey.d.ts +45 -5
  17. package/dist/internals/getQueryKey.d.ts.map +1 -1
  18. package/dist/internals/useHookResult.d.ts +10 -0
  19. package/dist/internals/useHookResult.d.ts.map +1 -0
  20. package/dist/internals/useQueries.d.ts +27 -27
  21. package/dist/internals/useQueries.d.ts.map +1 -1
  22. package/dist/queryClient-1c8d7d8a.js +8 -0
  23. package/dist/server/index.d.ts +2 -0
  24. package/dist/server/index.d.ts.map +1 -0
  25. package/dist/server/index.js +108 -0
  26. package/dist/server/index.mjs +104 -0
  27. package/dist/server/ssgProxy.d.ts +48 -0
  28. package/dist/server/ssgProxy.d.ts.map +1 -0
  29. package/dist/shared/hooks/createHooksInternal.d.ts +49 -129
  30. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  31. package/dist/shared/hooks/createRootHooks.d.ts +2 -0
  32. package/dist/shared/hooks/createRootHooks.d.ts.map +1 -0
  33. package/dist/shared/hooks/types.d.ts +109 -0
  34. package/dist/shared/hooks/types.d.ts.map +1 -0
  35. package/dist/shared/index.d.ts +21 -8
  36. package/dist/shared/index.d.ts.map +1 -1
  37. package/dist/shared/index.js +8 -5
  38. package/dist/shared/index.mjs +3 -3
  39. package/dist/shared/polymorphism/index.d.ts +5 -0
  40. package/dist/shared/polymorphism/index.d.ts.map +1 -0
  41. package/dist/shared/polymorphism/mutationLike.d.ts +18 -0
  42. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -0
  43. package/dist/shared/polymorphism/queryLike.d.ts +18 -0
  44. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -0
  45. package/dist/shared/polymorphism/routerLike.d.ts +10 -0
  46. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -0
  47. package/dist/shared/polymorphism/utilsLike.d.ts +7 -0
  48. package/dist/shared/polymorphism/utilsLike.d.ts.map +1 -0
  49. package/dist/shared/proxy/decorationProxy.d.ts +7 -7
  50. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
  51. package/dist/shared/proxy/useQueriesProxy.d.ts +17 -17
  52. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  53. package/dist/shared/proxy/utilsProxy.d.ts +95 -83
  54. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  55. package/dist/shared/queryClient.d.ts +15 -15
  56. package/dist/shared/queryClient.d.ts.map +1 -1
  57. package/dist/shared/types.d.ts +40 -37
  58. package/dist/shared/types.d.ts.map +1 -1
  59. package/dist/utils/inferReactQueryProcedure.d.ts +23 -10
  60. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  61. package/dist/utilsProxy-11521789.js +114 -0
  62. package/dist/utilsProxy-981e4875.js +128 -0
  63. package/dist/utilsProxy-d4d71107.mjs +121 -0
  64. package/package.json +28 -19
  65. package/server/index.d.ts +1 -0
  66. package/server/index.js +1 -0
  67. package/src/createTRPCReact.tsx +131 -87
  68. package/src/index.ts +1 -1
  69. package/src/internals/context.tsx +102 -156
  70. package/src/internals/getClientArgs.ts +12 -0
  71. package/src/internals/getQueryKey.ts +122 -7
  72. package/src/internals/useHookResult.ts +18 -0
  73. package/src/internals/useQueries.ts +9 -4
  74. package/src/server/index.ts +1 -0
  75. package/src/server/ssgProxy.ts +243 -0
  76. package/src/shared/hooks/createHooksInternal.tsx +295 -452
  77. package/src/shared/hooks/createRootHooks.tsx +4 -0
  78. package/src/shared/hooks/types.ts +247 -0
  79. package/src/shared/index.ts +19 -1
  80. package/src/shared/polymorphism/index.ts +4 -0
  81. package/src/shared/polymorphism/mutationLike.ts +31 -0
  82. package/src/shared/polymorphism/queryLike.ts +32 -0
  83. package/src/shared/polymorphism/routerLike.ts +23 -0
  84. package/src/shared/polymorphism/utilsLike.ts +8 -0
  85. package/src/shared/proxy/decorationProxy.ts +12 -21
  86. package/src/shared/proxy/useQueriesProxy.ts +14 -18
  87. package/src/shared/proxy/utilsProxy.ts +149 -93
  88. package/src/shared/types.ts +10 -6
  89. package/src/utils/inferReactQueryProcedure.ts +40 -5
  90. package/dist/createHooksInternal-10b1b7ef.mjs +0 -466
  91. package/dist/createHooksInternal-860b8183.js +0 -476
  92. package/dist/getArrayQueryKey-30a7f2f6.mjs +0 -29
  93. package/dist/getArrayQueryKey-671d083c.js +0 -31
  94. package/dist/internals/getArrayQueryKey.d.ts +0 -13
  95. package/dist/internals/getArrayQueryKey.d.ts.map +0 -1
  96. package/dist/interop.d.ts +0 -11
  97. package/dist/interop.d.ts.map +0 -1
  98. package/dist/ssg/index.d.ts +0 -5
  99. package/dist/ssg/index.d.ts.map +0 -1
  100. package/dist/ssg/index.js +0 -126
  101. package/dist/ssg/index.mjs +0 -121
  102. package/dist/ssg/ssg.d.ts +0 -23
  103. package/dist/ssg/ssg.d.ts.map +0 -1
  104. package/dist/ssg/ssgProxy.d.ts +0 -37
  105. package/dist/ssg/ssgProxy.d.ts.map +0 -1
  106. package/src/internals/getArrayQueryKey.test.ts +0 -76
  107. package/src/internals/getArrayQueryKey.ts +0 -30
  108. package/src/interop.ts +0 -29
  109. package/src/ssg/index.ts +0 -4
  110. package/src/ssg/ssg.ts +0 -144
  111. package/src/ssg/ssgProxy.ts +0 -108
  112. package/ssg/index.d.ts +0 -1
  113. package/ssg/index.js +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) <year> <author>
3
+ Copyright (c) 2023 Alex Johansson
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -38,7 +38,7 @@ pnpm add @trpc/react-query @tanstack/react-query
38
38
  Create a utils file that exports tRPC hooks and providers.
39
39
 
40
40
  ```ts
41
- import { createReactQueryHooks, createTRPCReact } from '@trpc/react-query';
41
+ import { createTRPCReact } from '@trpc/react-query';
42
42
  import type { AppRouter } from './server';
43
43
 
44
44
  export const trpc = createTRPCReact<AppRouter>();
@@ -48,9 +48,8 @@ Use the provider to connect to your API.
48
48
 
49
49
  ```ts
50
50
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
51
- import React from 'react';
52
- import { useState } from 'react';
53
51
  import { trpc } from '~/utils/trpc';
52
+ import React, { useState } from 'react';
54
53
 
55
54
  export function App() {
56
55
  const [queryClient] = useState(() => new QueryClient());
@@ -72,10 +71,10 @@ export function App() {
72
71
  Now in any component, you can query your API using the proxy exported from the utils file.
73
72
 
74
73
  ```ts
75
- import { proxy } from '~/utils/trpc';
74
+ import { trpc } from '~/utils/trpc';
76
75
 
77
76
  export function Hello() {
78
- const { data, error, status } = proxy.greeting.useQuery({ name: 'tRPC' });
77
+ const { data, error, status } = trpc.greeting.useQuery({ name: 'tRPC' });
79
78
 
80
79
  if (error) {
81
80
  return <p>{error.message}</p>;
@@ -0,0 +1,396 @@
1
+ import { createRecursiveProxy } from '@trpc/server/shared';
2
+ import { useQuery, useQueryClient, useMutation, hashKey, useInfiniteQuery, useQueries } from '@tanstack/react-query';
3
+ import { createTRPCUntypedClient } from '@trpc/client';
4
+ import React, { useRef, useState, useEffect, useCallback, useMemo } from 'react';
5
+ import { a as getQueryKeyInternal, T as TRPCContext } from './utilsProxy-11521789.js';
6
+
7
+ /**
8
+ * Create proxy for decorating procedures
9
+ * @internal
10
+ */
11
+ function createReactProxyDecoration(name, hooks) {
12
+ return createRecursiveProxy(({ path, args }) => {
13
+ const pathCopy = [name, ...path];
14
+ // The last arg is for instance `.useMutation` or `.useQuery()`
15
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
+ const lastArg = pathCopy.pop();
17
+ if (lastArg === 'useMutation') {
18
+ return hooks[lastArg](pathCopy, ...args);
19
+ }
20
+ if (lastArg === '_def') {
21
+ return {
22
+ path: pathCopy,
23
+ };
24
+ }
25
+ const [input, ...rest] = args;
26
+ const opts = rest[0] || {};
27
+ return hooks[lastArg](pathCopy, input, opts);
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Create proxy for `useQueries` options
33
+ * @internal
34
+ */
35
+ function createUseQueriesProxy(client) {
36
+ return createRecursiveProxy((opts) => {
37
+ const arrayPath = opts.path;
38
+ const dotPath = arrayPath.join('.');
39
+ const [input, ...rest] = opts.args;
40
+ const options = {
41
+ queryKey: getQueryKeyInternal(arrayPath, input, 'query'),
42
+ queryFn: () => {
43
+ return client.query(dotPath, input);
44
+ },
45
+ ...rest[0],
46
+ };
47
+ return options;
48
+ });
49
+ }
50
+
51
+ function getClientArgs(queryKey, opts, pageParam) {
52
+ const path = queryKey[0];
53
+ const input = queryKey[1]?.input;
54
+ if (pageParam)
55
+ input.cursor = pageParam;
56
+ return [path.join('.'), input, opts?.trpc];
57
+ }
58
+
59
+ /**
60
+ * Makes a stable reference of the `trpc` prop
61
+ */
62
+ function useHookResult(value) {
63
+ const ref = useRef(value);
64
+ ref.current.path = value.path;
65
+ return ref.current;
66
+ }
67
+
68
+ /**
69
+ * @internal
70
+ */
71
+ function createRootHooks(config) {
72
+ const mutationSuccessOverride = config?.overrides?.useMutation?.onSuccess ??
73
+ ((options) => options.originalFn());
74
+ const Context = (config?.context ??
75
+ TRPCContext);
76
+ const createClient = (opts) => {
77
+ return createTRPCUntypedClient(opts);
78
+ };
79
+ const TRPCProvider = (props) => {
80
+ const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
81
+ const [ssrState, setSSRState] = useState(props.ssrState ?? false);
82
+ useEffect(() => {
83
+ // Only updating state to `mounted` if we are using SSR.
84
+ // This makes it so we don't have an unnecessary re-render when opting out of SSR.
85
+ setSSRState((state) => (state ? 'mounted' : false));
86
+ }, []);
87
+ return (React.createElement(Context.Provider, { value: {
88
+ abortOnUnmount,
89
+ queryClient,
90
+ client,
91
+ ssrContext: ssrContext ?? null,
92
+ ssrState,
93
+ fetchQuery: useCallback((queryKey, opts) => {
94
+ return queryClient.fetchQuery({
95
+ ...opts,
96
+ queryKey,
97
+ queryFn: () => client.query(...getClientArgs(queryKey, opts)),
98
+ });
99
+ }, [client, queryClient]),
100
+ fetchInfiniteQuery: useCallback((queryKey, opts) => {
101
+ return queryClient.fetchInfiniteQuery({
102
+ ...opts,
103
+ queryKey,
104
+ queryFn: ({ pageParam }) => {
105
+ return client.query(...getClientArgs(queryKey, opts, pageParam));
106
+ },
107
+ defaultPageParam: opts?.initialCursor ?? null,
108
+ });
109
+ }, [client, queryClient]),
110
+ prefetchQuery: useCallback((queryKey, opts) => {
111
+ return queryClient.prefetchQuery({
112
+ ...opts,
113
+ queryKey,
114
+ queryFn: () => client.query(...getClientArgs(queryKey, opts)),
115
+ });
116
+ }, [client, queryClient]),
117
+ prefetchInfiniteQuery: useCallback((queryKey, opts) => {
118
+ return queryClient.prefetchInfiniteQuery({
119
+ ...opts,
120
+ queryKey,
121
+ queryFn: ({ pageParam }) => {
122
+ return client.query(...getClientArgs(queryKey, opts, pageParam));
123
+ },
124
+ defaultPageParam: opts?.initialCursor ?? null,
125
+ });
126
+ }, [client, queryClient]),
127
+ ensureQueryData: useCallback((queryKey, opts) => {
128
+ return queryClient.ensureQueryData({
129
+ ...opts,
130
+ queryKey,
131
+ queryFn: () => client.query(...getClientArgs(queryKey, opts)),
132
+ });
133
+ }, [client, queryClient]),
134
+ invalidateQueries: useCallback((queryKey, filters, options) => {
135
+ return queryClient.invalidateQueries({
136
+ ...filters,
137
+ queryKey,
138
+ }, options);
139
+ }, [queryClient]),
140
+ resetQueries: useCallback((queryKey, filters, options) => {
141
+ return queryClient.resetQueries({
142
+ ...filters,
143
+ queryKey,
144
+ }, options);
145
+ }, [queryClient]),
146
+ refetchQueries: useCallback((queryKey, filters, options) => {
147
+ return queryClient.refetchQueries({
148
+ ...filters,
149
+ queryKey,
150
+ }, options);
151
+ }, [queryClient]),
152
+ cancelQuery: useCallback((queryKey, options) => {
153
+ return queryClient.cancelQueries({
154
+ queryKey,
155
+ }, options);
156
+ }, [queryClient]),
157
+ setQueryData: useCallback((queryKey, updater, options) => {
158
+ return queryClient.setQueryData(queryKey, updater, options);
159
+ }, [queryClient]),
160
+ getQueryData: useCallback(
161
+ // REVIEW: Should this take opts?? The types doesn't have it
162
+ (queryKey) => {
163
+ return queryClient.getQueryData(queryKey);
164
+ }, [queryClient]),
165
+ setInfiniteQueryData: useCallback((queryKey, updater, options) => {
166
+ return queryClient.setQueryData(queryKey, updater, options);
167
+ }, [queryClient]),
168
+ getInfiniteQueryData: useCallback((queryKey) => {
169
+ return queryClient.getQueryData(queryKey);
170
+ }, [queryClient]),
171
+ } }, props.children));
172
+ };
173
+ function useContext() {
174
+ return React.useContext(Context);
175
+ }
176
+ /**
177
+ * Hack to make sure errors return `status`='error` when doing SSR
178
+ * @link https://github.com/trpc/trpc/pull/1645
179
+ */
180
+ function useSSRQueryOptionsIfNeeded(queryKey, opts) {
181
+ const { queryClient, ssrState } = useContext();
182
+ return ssrState &&
183
+ ssrState !== 'mounted' &&
184
+ queryClient.getQueryCache().find({ queryKey })?.state.status === 'error'
185
+ ? {
186
+ retryOnMount: false,
187
+ ...opts,
188
+ }
189
+ : opts;
190
+ }
191
+ function useQuery$1(path, input, opts) {
192
+ const context = useContext();
193
+ if (!context) {
194
+ throw new Error('Unable to retrieve application context. Did you forget to wrap your App inside `withTRPC` HoC?');
195
+ }
196
+ const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
197
+ const queryKey = getQueryKeyInternal(path, input, 'query');
198
+ const defaultOpts = queryClient.getQueryDefaults(queryKey);
199
+ if (typeof window === 'undefined' &&
200
+ ssrState === 'prepass' &&
201
+ opts?.trpc?.ssr !== false &&
202
+ (opts?.enabled ?? defaultOpts?.enabled) !== false &&
203
+ !queryClient.getQueryCache().find({ queryKey })) {
204
+ void prefetchQuery(queryKey, opts);
205
+ }
206
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
207
+ ...defaultOpts,
208
+ ...opts,
209
+ });
210
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
211
+ const hook = useQuery({
212
+ ...ssrOpts,
213
+ queryKey: queryKey,
214
+ queryFn: (queryFunctionContext) => {
215
+ const actualOpts = {
216
+ ...ssrOpts,
217
+ trpc: {
218
+ ...ssrOpts?.trpc,
219
+ ...(shouldAbortOnUnmount
220
+ ? { signal: queryFunctionContext.signal }
221
+ : {}),
222
+ },
223
+ };
224
+ return client.query(...getClientArgs(queryKey, actualOpts));
225
+ },
226
+ }, queryClient);
227
+ hook.trpc = useHookResult({
228
+ path: path.join('.'),
229
+ });
230
+ return hook;
231
+ }
232
+ function useSuspenseQuery(path, input, opts) {
233
+ const hookResult = useQuery$1(path, input, {
234
+ ...opts,
235
+ suspense: true,
236
+ enabled: true,
237
+ throwOnError: true,
238
+ });
239
+ return [hookResult.data, hookResult];
240
+ }
241
+ function useMutation$1(path, opts) {
242
+ const { client } = useContext();
243
+ const queryClient = useQueryClient();
244
+ const mutationKey = [path];
245
+ const defaultOpts = queryClient.getMutationDefaults(mutationKey);
246
+ const hook = useMutation({
247
+ ...opts,
248
+ mutationKey: mutationKey,
249
+ mutationFn: (input) => {
250
+ return client.mutation(...getClientArgs([path, { input }], opts));
251
+ },
252
+ onSuccess(...args) {
253
+ const originalFn = () => opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
254
+ return mutationSuccessOverride({
255
+ originalFn,
256
+ queryClient,
257
+ meta: opts?.meta ?? defaultOpts?.meta ?? {},
258
+ });
259
+ },
260
+ }, queryClient);
261
+ hook.trpc = useHookResult({
262
+ path: path.join('.'),
263
+ });
264
+ return hook;
265
+ }
266
+ /* istanbul ignore next -- @preserve */
267
+ function useSubscription(path, input, opts) {
268
+ const enabled = opts?.enabled ?? true;
269
+ const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
270
+ const { client } = useContext();
271
+ const optsRef = useRef(opts);
272
+ optsRef.current = opts;
273
+ useEffect(() => {
274
+ if (!enabled) {
275
+ return;
276
+ }
277
+ let isStopped = false;
278
+ const subscription = client.subscription(path.join('.'), input ?? undefined, {
279
+ onStarted: () => {
280
+ if (!isStopped) {
281
+ optsRef.current.onStarted?.();
282
+ }
283
+ },
284
+ onData: (data) => {
285
+ if (!isStopped) {
286
+ opts.onData(data);
287
+ }
288
+ },
289
+ onError: (err) => {
290
+ if (!isStopped) {
291
+ optsRef.current.onError?.(err);
292
+ }
293
+ },
294
+ });
295
+ return () => {
296
+ isStopped = true;
297
+ subscription.unsubscribe();
298
+ };
299
+ // eslint-disable-next-line react-hooks/exhaustive-deps
300
+ }, [queryKey, enabled]);
301
+ }
302
+ function useInfiniteQuery$1(path, input, opts) {
303
+ const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount, } = useContext();
304
+ const queryKey = getQueryKeyInternal(path, input, 'infinite');
305
+ const defaultOpts = queryClient.getQueryDefaults(queryKey);
306
+ if (typeof window === 'undefined' &&
307
+ ssrState === 'prepass' &&
308
+ opts?.trpc?.ssr !== false &&
309
+ (opts?.enabled ?? defaultOpts?.enabled) !== false &&
310
+ !queryClient.getQueryCache().find({ queryKey })) {
311
+ void prefetchInfiniteQuery(queryKey, { ...defaultOpts, ...opts });
312
+ }
313
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
314
+ ...defaultOpts,
315
+ ...opts,
316
+ });
317
+ // request option should take priority over global
318
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
319
+ const hook = useInfiniteQuery({
320
+ ...ssrOpts,
321
+ defaultPageParam: opts.initialCursor ?? null,
322
+ queryKey: queryKey,
323
+ queryFn: (queryFunctionContext) => {
324
+ const actualOpts = {
325
+ ...ssrOpts,
326
+ trpc: {
327
+ ...ssrOpts?.trpc,
328
+ ...(shouldAbortOnUnmount
329
+ ? { signal: queryFunctionContext.signal }
330
+ : {}),
331
+ },
332
+ };
333
+ return client.query(...getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
334
+ },
335
+ }, queryClient);
336
+ hook.trpc = useHookResult({
337
+ // REVIEW: What do we want to return here?
338
+ path: path.join('.'),
339
+ });
340
+ return hook;
341
+ }
342
+ function useSuspenseInfiniteQuery(path, input, opts) {
343
+ const hookResult = useInfiniteQuery$1(path, input, {
344
+ ...opts,
345
+ suspense: true,
346
+ enabled: true,
347
+ throwOnError: true,
348
+ });
349
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
350
+ return [hookResult.data, hookResult];
351
+ }
352
+ const useQueries$1 = (queriesCallback) => {
353
+ const { ssrState, queryClient, prefetchQuery, client } = useContext();
354
+ const proxy = createUseQueriesProxy(client);
355
+ const queries = queriesCallback(proxy);
356
+ if (typeof window === 'undefined' && ssrState === 'prepass') {
357
+ for (const query of queries) {
358
+ const queryOption = query;
359
+ if (queryOption.trpc?.ssr !== false &&
360
+ !queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })) {
361
+ void prefetchQuery(queryOption.queryKey, queryOption);
362
+ }
363
+ }
364
+ }
365
+ return useQueries({
366
+ queries: queries.map((query) => ({
367
+ ...query,
368
+ queryKey: query.queryKey,
369
+ })),
370
+ }, queryClient);
371
+ };
372
+ const useDehydratedState = (client, trpcState) => {
373
+ const transformed = useMemo(() => {
374
+ if (!trpcState) {
375
+ return trpcState;
376
+ }
377
+ return client.runtime.transformer.deserialize(trpcState);
378
+ }, [trpcState, client]);
379
+ return transformed;
380
+ };
381
+ return {
382
+ Provider: TRPCProvider,
383
+ createClient,
384
+ useContext,
385
+ useQuery: useQuery$1,
386
+ useSuspenseQuery,
387
+ useQueries: useQueries$1,
388
+ useMutation: useMutation$1,
389
+ useSubscription,
390
+ useDehydratedState,
391
+ useInfiniteQuery: useInfiniteQuery$1,
392
+ useSuspenseInfiniteQuery,
393
+ };
394
+ }
395
+
396
+ export { createReactProxyDecoration as a, createUseQueriesProxy as b, createRootHooks as c, getClientArgs as g };