@tanstack/preact-query 5.102.4 → 5.102.5
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/build/legacy/QueryErrorResetBoundary.cjs +11 -9
- package/build/legacy/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.cts +11 -9
- package/build/legacy/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.d.ts +11 -9
- package/build/legacy/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/legacy/QueryErrorResetBoundary.js +11 -9
- package/build/legacy/QueryErrorResetBoundary.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +28 -24
- package/build/legacy/useInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +28 -24
- package/build/legacy/useInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +14 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +14 -0
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +14 -0
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +14 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +104 -1
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +104 -1
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +104 -1
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +104 -1
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +54 -2
- package/build/legacy/useQuery.d.cts.map +1 -1
- package/build/legacy/useQuery.d.ts +54 -2
- package/build/legacy/useQuery.d.ts.map +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.cjs +16 -8
- package/build/legacy/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.cts +16 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.d.ts +16 -8
- package/build/legacy/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseInfiniteQuery.js +16 -8
- package/build/legacy/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +74 -6
- package/build/legacy/useSuspenseQueries.d.cts.map +1 -1
- package/build/legacy/useSuspenseQueries.d.ts +74 -6
- package/build/legacy/useSuspenseQueries.d.ts.map +1 -1
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/legacy/useSuspenseQuery.cjs +4 -0
- package/build/legacy/useSuspenseQuery.cjs.map +1 -1
- package/build/legacy/useSuspenseQuery.d.cts +4 -0
- package/build/legacy/useSuspenseQuery.d.cts.map +1 -1
- package/build/legacy/useSuspenseQuery.d.ts +4 -0
- package/build/legacy/useSuspenseQuery.d.ts.map +1 -1
- package/build/legacy/useSuspenseQuery.js +4 -0
- package/build/legacy/useSuspenseQuery.js.map +1 -1
- package/build/modern/QueryErrorResetBoundary.cjs +11 -9
- package/build/modern/QueryErrorResetBoundary.cjs.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.cts +11 -9
- package/build/modern/QueryErrorResetBoundary.d.cts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.d.ts +11 -9
- package/build/modern/QueryErrorResetBoundary.d.ts.map +1 -1
- package/build/modern/QueryErrorResetBoundary.js +11 -9
- package/build/modern/QueryErrorResetBoundary.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +28 -24
- package/build/modern/useInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useInfiniteQuery.d.ts +28 -24
- package/build/modern/useInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +14 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +14 -0
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +14 -0
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +14 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +104 -1
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +104 -1
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +104 -1
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +104 -1
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +54 -2
- package/build/modern/useQuery.d.cts.map +1 -1
- package/build/modern/useQuery.d.ts +54 -2
- package/build/modern/useQuery.d.ts.map +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.cjs +16 -8
- package/build/modern/useSuspenseInfiniteQuery.cjs.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.cts +16 -8
- package/build/modern/useSuspenseInfiniteQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.d.ts +16 -8
- package/build/modern/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseInfiniteQuery.js +16 -8
- package/build/modern/useSuspenseInfiniteQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +74 -6
- package/build/modern/useSuspenseQueries.d.cts.map +1 -1
- package/build/modern/useSuspenseQueries.d.ts +74 -6
- package/build/modern/useSuspenseQueries.d.ts.map +1 -1
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/build/modern/useSuspenseQuery.cjs +4 -0
- package/build/modern/useSuspenseQuery.cjs.map +1 -1
- package/build/modern/useSuspenseQuery.d.cts +4 -0
- package/build/modern/useSuspenseQuery.d.cts.map +1 -1
- package/build/modern/useSuspenseQuery.d.ts +4 -0
- package/build/modern/useSuspenseQuery.d.ts.map +1 -1
- package/build/modern/useSuspenseQuery.js +4 -0
- package/build/modern/useSuspenseQuery.js.map +1 -1
- package/package.json +3 -3
- package/src/QueryErrorResetBoundary.tsx +11 -9
- package/src/useInfiniteQuery.ts +28 -24
- package/src/useIsFetching.ts +14 -0
- package/src/useMutation.ts +104 -1
- package/src/useQuery.ts +54 -2
- package/src/useSuspenseInfiniteQuery.ts +16 -8
- package/src/useSuspenseQueries.ts +74 -6
- package/src/useSuspenseQuery.ts +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.d.cts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFxC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;;;;;EAKhE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFa,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBAAsB,uBAAuB;;;;;EAK7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
|
|
@@ -87,7 +87,7 @@ type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> =
|
|
|
87
87
|
*
|
|
88
88
|
* function Posts({ ids }: { ids: Array<number> }) {
|
|
89
89
|
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
90
|
-
* const
|
|
90
|
+
* const postQueries = useSuspenseQueries({
|
|
91
91
|
* queries: ids.map((id) => ({
|
|
92
92
|
* queryKey: ['post', id],
|
|
93
93
|
* queryFn: () => fetchPost(id),
|
|
@@ -96,8 +96,8 @@ type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> =
|
|
|
96
96
|
*
|
|
97
97
|
* return (
|
|
98
98
|
* <ul>
|
|
99
|
-
* {
|
|
100
|
-
* <li key={
|
|
99
|
+
* {postQueries.map((query) => (
|
|
100
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
101
101
|
* ))}
|
|
102
102
|
* </ul>
|
|
103
103
|
* )
|
|
@@ -111,6 +111,40 @@ type SuspenseQueriesResults<T extends Array<any>, TResults extends Array<any> =
|
|
|
111
111
|
* )
|
|
112
112
|
* }
|
|
113
113
|
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
117
|
+
* they fetch in parallel rather than suspending one after another:
|
|
118
|
+
* ```tsx
|
|
119
|
+
* import { Suspense } from 'preact/compat'
|
|
120
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
121
|
+
*
|
|
122
|
+
* function Dashboard() {
|
|
123
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
124
|
+
* queries: [
|
|
125
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
126
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
127
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
128
|
+
* ],
|
|
129
|
+
* })
|
|
130
|
+
*
|
|
131
|
+
* return (
|
|
132
|
+
* <div>
|
|
133
|
+
* <UserList users={usersQuery.data} />
|
|
134
|
+
* <TeamList teams={teamsQuery.data} />
|
|
135
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
136
|
+
* </div>
|
|
137
|
+
* )
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* function App() {
|
|
141
|
+
* return (
|
|
142
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
143
|
+
* <Dashboard />
|
|
144
|
+
* </Suspense>
|
|
145
|
+
* )
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
114
148
|
*/
|
|
115
149
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
116
150
|
/**
|
|
@@ -145,7 +179,7 @@ declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = Susp
|
|
|
145
179
|
*
|
|
146
180
|
* function Posts({ ids }: { ids: Array<number> }) {
|
|
147
181
|
* // Every result is guaranteed to be defined — no per-query `isPending` check needed.
|
|
148
|
-
* const
|
|
182
|
+
* const postQueries = useSuspenseQueries({
|
|
149
183
|
* queries: ids.map((id) => ({
|
|
150
184
|
* queryKey: ['post', id],
|
|
151
185
|
* queryFn: () => fetchPost(id),
|
|
@@ -154,8 +188,8 @@ declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = Susp
|
|
|
154
188
|
*
|
|
155
189
|
* return (
|
|
156
190
|
* <ul>
|
|
157
|
-
* {
|
|
158
|
-
* <li key={
|
|
191
|
+
* {postQueries.map((query) => (
|
|
192
|
+
* <li key={query.data.id}>{query.data.title}</li>
|
|
159
193
|
* ))}
|
|
160
194
|
* </ul>
|
|
161
195
|
* )
|
|
@@ -169,6 +203,40 @@ declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = Susp
|
|
|
169
203
|
* )
|
|
170
204
|
* }
|
|
171
205
|
* ```
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so
|
|
209
|
+
* they fetch in parallel rather than suspending one after another:
|
|
210
|
+
* ```tsx
|
|
211
|
+
* import { Suspense } from 'preact/compat'
|
|
212
|
+
* import { useSuspenseQueries } from '@tanstack/preact-query'
|
|
213
|
+
*
|
|
214
|
+
* function Dashboard() {
|
|
215
|
+
* const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({
|
|
216
|
+
* queries: [
|
|
217
|
+
* { queryKey: ['users'], queryFn: fetchUsers },
|
|
218
|
+
* { queryKey: ['teams'], queryFn: fetchTeams },
|
|
219
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
220
|
+
* ],
|
|
221
|
+
* })
|
|
222
|
+
*
|
|
223
|
+
* return (
|
|
224
|
+
* <div>
|
|
225
|
+
* <UserList users={usersQuery.data} />
|
|
226
|
+
* <TeamList teams={teamsQuery.data} />
|
|
227
|
+
* <ProjectList projects={projectsQuery.data} />
|
|
228
|
+
* </div>
|
|
229
|
+
* )
|
|
230
|
+
* }
|
|
231
|
+
*
|
|
232
|
+
* function App() {
|
|
233
|
+
* return (
|
|
234
|
+
* <Suspense fallback={<h1>Loading dashboard...</h1>}>
|
|
235
|
+
* <Dashboard />
|
|
236
|
+
* </Suspense>
|
|
237
|
+
* )
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
172
240
|
*/
|
|
173
241
|
declare function useSuspenseQueries<T extends Array<any>, TCombinedResult = SuspenseQueriesResults<T>>(options: {
|
|
174
242
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.d.ts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.d.ts","names":[],"sources":["../../src/useSuspenseQueries.ts"],"mappings":";;;KAaK;KAGA;KAEA,2BAA2B,KAE9B;EACE,mBAAmB;EACnB,cAAc;EACd,YAAY;IAEV,wBAAwB,cAAc,QAAQ,SAC9C;EAAY,mBAAmB;EAAc,cAAc;IACzD,wBAAwB,cAAc,UACtC;EAAY,YAAY;EAAO,cAAc;IAC3C,iCAAiC,QAAQ,SAEzC,iBAAiB,oBAAoB,cAAc,SACjD,wBAAwB,cAAc,QAAQ,SAC9C,iBAAiB,oBAAoB,UACnC,wBAAwB,cAAc,UACtC,iBAAiB,gBACf,wBAAwB,gBAExB;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,OACA,aAEF;EACI,UACI,oBAAoB,oBAAoB,aACxC;EACJ,eAAe,wBAAwB;IAEzC,wBACE,cACA,QACA,cACA,aAGF;KAEf,0BAA0B,KAE7B;EAAY;EAAkB,cAAc;EAAQ,YAAY;IAC5D,uBAAuB,OAAO,UAC9B;EAAY,mBAAmB;EAAc,cAAc;IACzD,uBAAuB,cAAc,UACrC;EAAY,YAAY;EAAO,cAAc;IAC3C,uBAAuB,OAAO,UAE9B,sBAAsB,cAAc,SAClC,uBAAuB,OAAO,UAC9B,iBAAiB,oBAAoB,UACnC,uBAAuB,cAAc,UACrC,iBAAiB,gBACf,uBAAuB,gBAEvB;EACI,UACI,oBAAoB,qBACpB;EACJ,UAAU,oBAAoB;EAC9B,eAAe,wBAAwB;IAEzC,uCACkB,QAAQ,eAAe,uBACvB,SAAS,eAAe,UAE1C;EACI,UACI,oBAAoB,qBACpB;EACJ,eAAe,wBAAwB;IAEzC,uBACE,8BACgB,SAAS,eAAe,UAG1C;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,2BACN,oBAEE,iBAAiB,YACX,UAAU,2BAA2B,SACzC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,2BAA2B,YACrC,cAEN,uBAAuB,IACrB,IAGA,UAAU,MACN,8BACQ,oBACA,cACA,aACA,cAGV,MACE,wBAAwB,cAAc,QAAQ,OAAO,cAGvD,MAAM;;;;;;;;;;;;;KAcR,uBACV,UAAU,YACV,iBAAiB,iBACjB,eAAe,8BACb,yBAAyB,gBACzB,MAAM,0BACN,oBAEE,iBAAiB,YACX,UAAU,0BAA0B,SACxC,iBAAiB,eAAe,SAC9B,2BACM,YACA,UAAU,0BAA0B,YACpC,iBAEH,WAAW,IAAI,0BAA0B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFxC,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBACiB,uBAAuB,sBACpB,WAAW,IAAI,2BAA2B,EAAE;;;;;EAKhE,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFa,mBACd,UAAU,YACV,kBAAkB,uBAAuB,IAEzC;;;;EAIE,sBAAsB,uBAAuB;;;;;EAK7C,WAAW,QAAQ,uBAAuB,OAAO;GAEnD,cAAc,cACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQueries.js","names":[],"sources":["../../src/useSuspenseQueries.ts"],"sourcesContent":["import { skipToken } from '@tanstack/query-core'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useQueries } from './useQueries'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseSuspenseQueryOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TQueryFnData,\n TQueryKey\n >\n : // Fallback\n UseSuspenseQueryOptions\n\ntype GetUseSuspenseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseSuspenseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseSuspenseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseSuspenseQueryResult\n\n/**\n * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every\n * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)\n * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a\n * single homogeneous {@link UseSuspenseQueryOptions} type.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryOptions>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryOptions<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesOptions<\n [...Tails],\n [...TResults, GetUseSuspenseQueryOptions<Head>],\n [...TDepth, 1]\n >\n : Array<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseSuspenseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n >\n : // Fallback\n Array<UseSuspenseQueryOptions>\n\n/**\n * The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors\n * {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.\n * A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20\n * elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesResults<\n [...Tails],\n [...TResults, GetUseSuspenseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have\n * `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const results = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {results.map((result) => (\n * <li key={result.data.id}>{result.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries:\n | readonly [...SuspenseQueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have\n * `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const results = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {results.map((result) => (\n * <li key={result.data.id}>{result.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries: readonly [...SuspenseQueriesOptions<T>]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\nexport function useSuspenseQueries(options: any, queryClient?: QueryClient) {\n return useQueries(\n {\n ...options,\n queries: options.queries.map((query: any) => {\n if (process.env.NODE_ENV !== 'production') {\n if (query.queryFn === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQueries')\n }\n }\n\n return {\n ...query,\n suspense: true,\n throwOnError: defaultThrowOnError,\n enabled: true,\n placeholderData: undefined,\n }\n }),\n },\n queryClient,\n )\n}\n"],"mappings":";;;;AA0TA,SAAgB,mBAAmB,SAAc,aAA2B;CAC1E,OAAO,WACL;EACE,GAAG;EACH,SAAS,QAAQ,QAAQ,KAAK,UAAe;GAC3C,IAAI,QAAQ,IAAI,aAAa,cACvB;QAAA,MAAM,YAAY,WACpB,QAAQ,MAAM,iDAAiD;GAAA;GAInE,OAAO;IACL,GAAG;IACH,UAAU;IACV,cAAc;IACd,SAAS;IACT,iBAAiB,KAAA;GACnB;EACF,CAAC;CACH,GACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useSuspenseQueries.js","names":[],"sources":["../../src/useSuspenseQueries.ts"],"sourcesContent":["import { skipToken } from '@tanstack/query-core'\nimport type {\n DefaultError,\n QueryClient,\n QueryFunction,\n ThrowOnError,\n} from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useQueries } from './useQueries'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetUseSuspenseQueryOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseSuspenseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryOptions<\n TQueryFnData,\n TError,\n TQueryFnData,\n TQueryKey\n >\n : // Fallback\n UseSuspenseQueryOptions\n\ntype GetUseSuspenseQueryResult<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseSuspenseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseSuspenseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseSuspenseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseSuspenseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseSuspenseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select?: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? UseSuspenseQueryResult<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n UseSuspenseQueryResult\n\n/**\n * The `queries` array accepted by `useSuspenseQueries`. Recursively unwraps each tuple element so every\n * entry's `queryFn`/`select` are inferred individually, up to 20 elements. An opaque array (e.g. `unknown[]`)\n * is returned as-is; a non-tuple array of a known element type, or a tuple past 20 elements, falls back to a\n * single homogeneous {@link UseSuspenseQueryOptions} type.\n *\n * @template T - The type of the `queries` array as written at the call site.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesOptions<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryOptions>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryOptions<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesOptions<\n [...Tails],\n [...TResults, GetUseSuspenseQueryOptions<Head>],\n [...TDepth, 1]\n >\n : Array<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogeneous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n UseSuspenseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n >\n : // Fallback\n Array<UseSuspenseQueryOptions>\n\n/**\n * The result type returned by `useSuspenseQueries`, when no `combine` is provided. Mirrors\n * {@link SuspenseQueriesOptions}: each tuple element's result type is inferred individually, up to 20 elements.\n * A non-tuple array is mapped per-element instead, still inferring each entry individually; only past 20\n * elements does this fall back to a single homogeneous {@link UseSuspenseQueryResult} type.\n *\n * @template T - The type of the `queries` array, as inferred by {@link SuspenseQueriesOptions}.\n * @template TResults - The internal accumulator that this type builds during recursion. It is not meant\n * to be set explicitly.\n * @template TDepth - The internal recursion-depth counter, checked against the 20-element limit. It is not\n * meant to be set explicitly.\n */\nexport type SuspenseQueriesResults<\n T extends Array<any>,\n TResults extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<UseSuspenseQueryResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResults, GetUseSuspenseQueryResult<Head>]\n : T extends [infer Head, ...infer Tails]\n ? SuspenseQueriesResults<\n [...Tails],\n [...TResults, GetUseSuspenseQueryResult<Head>],\n [...TDepth, 1]\n >\n : { [K in keyof T]: GetUseSuspenseQueryResult<T[K]> }\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have\n * `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const postQueries = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query) => (\n * <li key={query.data.id}>{query.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * )\n * }\n * ```\n *\n * @example\n * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so\n * they fetch in parallel rather than suspending one after another:\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Dashboard() {\n * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({\n * queries: [\n * { queryKey: ['users'], queryFn: fetchUsers },\n * { queryKey: ['teams'], queryFn: fetchTeams },\n * { queryKey: ['projects'], queryFn: fetchProjects },\n * ],\n * })\n *\n * return (\n * <div>\n * <UserList users={usersQuery.data} />\n * <TeamList teams={teamsQuery.data} />\n * <ProjectList projects={projectsQuery.data} />\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading dashboard...</h1>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries:\n | readonly [...SuspenseQueriesOptions<T>]\n | readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\n/**\n * The options for `useSuspenseQueries` are the same as for `useQueries`, except that each `query` can't have\n * `throwOnError`, `enabled`, or `placeholderData`.\n *\n * @param options - The `queries` array to run in Suspense, and an optional `combine` function.\n * @param queryClient - Use this to provide a custom `QueryClient`. Otherwise, the one from the nearest context\n * will be used.\n * @returns The same structure as `useQueries`, except that for each `query`, `data` is guaranteed to be\n * defined, `isPlaceholderData` is missing, and `status` is either `success` or `error` (with the derived\n * flags set accordingly).\n *\n * Caveat: the component will only re-mount after all queries have finished loading. Hence, if a query has gone\n * stale in the time it took for all the queries to complete, it will be fetched again at re-mount. To avoid\n * this, make sure to set a high enough `staleTime`. Cancellation does not work.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Posts({ ids }: { ids: Array<number> }) {\n * // Every result is guaranteed to be defined — no per-query `isPending` check needed.\n * const postQueries = useSuspenseQueries({\n * queries: ids.map((id) => ({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })),\n * })\n *\n * return (\n * <ul>\n * {postQueries.map((query) => (\n * <li key={query.data.id}>{query.data.title}</li>\n * ))}\n * </ul>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts ids={[1, 2, 3]} />\n * </Suspense>\n * )\n * }\n * ```\n *\n * @example\n * Several different queries — use `useSuspenseQueries` instead of multiple `useSuspenseQuery` calls, so\n * they fetch in parallel rather than suspending one after another:\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQueries } from '@tanstack/preact-query'\n *\n * function Dashboard() {\n * const [usersQuery, teamsQuery, projectsQuery] = useSuspenseQueries({\n * queries: [\n * { queryKey: ['users'], queryFn: fetchUsers },\n * { queryKey: ['teams'], queryFn: fetchTeams },\n * { queryKey: ['projects'], queryFn: fetchProjects },\n * ],\n * })\n *\n * return (\n * <div>\n * <UserList users={usersQuery.data} />\n * <TeamList teams={teamsQuery.data} />\n * <ProjectList projects={projectsQuery.data} />\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading dashboard...</h1>}>\n * <Dashboard />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQueries<\n T extends Array<any>,\n TCombinedResult = SuspenseQueriesResults<T>,\n>(\n options: {\n /**\n * An array with query option objects identical to `useSuspenseQuery`.\n */\n queries: readonly [...SuspenseQueriesOptions<T>]\n /**\n * Use this to combine the results of the queries into a single value. The result will be structurally\n * shared to be as referentially stable as possible.\n */\n combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult\n\nexport function useSuspenseQueries(options: any, queryClient?: QueryClient) {\n return useQueries(\n {\n ...options,\n queries: options.queries.map((query: any) => {\n if (process.env.NODE_ENV !== 'production') {\n if (query.queryFn === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQueries')\n }\n }\n\n return {\n ...query,\n suspense: true,\n throwOnError: defaultThrowOnError,\n enabled: true,\n placeholderData: undefined,\n }\n }),\n },\n queryClient,\n )\n}\n"],"mappings":";;;;AA8XA,SAAgB,mBAAmB,SAAc,aAA2B;CAC1E,OAAO,WACL;EACE,GAAG;EACH,SAAS,QAAQ,QAAQ,KAAK,UAAe;GAC3C,IAAI,QAAQ,IAAI,aAAa,cACvB;QAAA,MAAM,YAAY,WACpB,QAAQ,MAAM,iDAAiD;GAAA;GAInE,OAAO;IACL,GAAG;IACH,UAAU;IACV,cAAc;IACd,SAAS;IACT,iBAAiB,KAAA;GACnB;EACF,CAAC;CACH,GACA,WACF;AACF"}
|
|
@@ -9,6 +9,10 @@ let _tanstack_query_core = require("@tanstack/query-core");
|
|
|
9
9
|
*
|
|
10
10
|
* Caveat: cancellation does not work.
|
|
11
11
|
*
|
|
12
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
13
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
14
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
15
|
+
* fetch in parallel.
|
|
12
16
|
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
13
17
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
14
18
|
* be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","QueryObserver"],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? <Spinner /> : null}</h1>\n * {data.map((post) => (\n * <p key={post.id}>{post.title}</p>\n * ))}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.cjs","names":["skipToken","useBaseQuery","defaultThrowOnError","QueryObserver"],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request\n * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.\n * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they\n * fetch in parallel.\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? <Spinner /> : null}</h1>\n * {data.map((post) => (\n * <p key={post.id}>{post.title}</p>\n * ))}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoBA,qBAAAA,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAOC,qBAAAA,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAcC,iBAAAA;EACd,iBAAiB,KAAA;CACnB,GACAC,qBAAAA,eACA,WACF;AACF"}
|
|
@@ -7,6 +7,10 @@ import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
|
|
|
7
7
|
*
|
|
8
8
|
* Caveat: cancellation does not work.
|
|
9
9
|
*
|
|
10
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
11
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
12
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
13
|
+
* fetch in parallel.
|
|
10
14
|
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
11
15
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
12
16
|
* be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.d.cts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.d.cts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -7,6 +7,10 @@ import { DefaultError, QueryClient, QueryKey } from "@tanstack/query-core";
|
|
|
7
7
|
*
|
|
8
8
|
* Caveat: cancellation does not work.
|
|
9
9
|
*
|
|
10
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
11
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
12
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
13
|
+
* fetch in parallel.
|
|
10
14
|
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
11
15
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
12
16
|
* be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.d.ts","names":[],"sources":["../../src/useSuspenseQuery.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsDgB,iBACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,wBAAwB,cAAc,QAAQ,OAAO,YAC9D,cAAc,cACb,uBAAuB,OAAO"}
|
|
@@ -8,6 +8,10 @@ import { QueryObserver, skipToken } from "@tanstack/query-core";
|
|
|
8
8
|
*
|
|
9
9
|
* Caveat: cancellation does not work.
|
|
10
10
|
*
|
|
11
|
+
* @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request
|
|
12
|
+
* waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.
|
|
13
|
+
* Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they
|
|
14
|
+
* fetch in parallel.
|
|
11
15
|
* @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.
|
|
12
16
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
13
17
|
* be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? <Spinner /> : null}</h1>\n * {data.map((post) => (\n * <p key={post.id}>{post.title}</p>\n * ))}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.js","names":[],"sources":["../../src/useSuspenseQuery.ts"],"sourcesContent":["import { QueryObserver, skipToken } from '@tanstack/query-core'\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\n\nimport { defaultThrowOnError } from './suspense'\nimport type { UseSuspenseQueryOptions, UseSuspenseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useSuspenseQuery` are the same as for `useQuery`, except for `throwOnError`, `enabled`, and\n * `placeholderData`.\n *\n * Caveat: cancellation does not work.\n *\n * @remarks Multiple `useSuspenseQuery` calls in the same component suspend serially, causing a request\n * waterfall — each one blocks rendering until it resolves, so the next doesn't even start fetching until then.\n * Use {@link useSuspenseQueries} instead when you have more than one suspenseful query in a component, so they\n * fetch in parallel.\n * @param options - The {@link UseSuspenseQueryOptions} to use — the same options as `useQuery`, minus the ones listed above.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same object as `useQuery`, except that `data` is guaranteed to be defined, `isPlaceholderData`\n * is missing, and `status` is either `success` or `error` (with the derived flags set accordingly).\n *\n * @example\n * ```tsx\n * import { Suspense } from 'preact/compat'\n * import { useSuspenseQuery } from '@tanstack/preact-query'\n *\n * function Posts() {\n * // `data` is guaranteed to be defined here — no `isPending` check needed.\n * const { data, isFetching } = useSuspenseQuery({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * return (\n * <div>\n * <h1>Posts {isFetching ? <Spinner /> : null}</h1>\n * {data.map((post) => (\n * <p key={post.id}>{post.title}</p>\n * ))}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <Suspense fallback={<h1>Loading posts...</h1>}>\n * <Posts />\n * </Suspense>\n * )\n * }\n * ```\n */\nexport function useSuspenseQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseSuspenseQueryResult<TData, TError> {\n if (process.env.NODE_ENV !== 'production') {\n if ((options.queryFn as any) === skipToken) {\n console.error('skipToken is not allowed for useSuspenseQuery')\n }\n }\n\n return useBaseQuery(\n {\n ...options,\n enabled: true,\n suspense: true,\n throwOnError: defaultThrowOnError,\n placeholderData: undefined,\n },\n QueryObserver,\n queryClient,\n ) as UseSuspenseQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,iBAMd,SACA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,cACtB;MAAA,QAAQ,YAAoB,WAC/B,QAAQ,MAAM,+CAA+C;CAAA;CAIjE,OAAO,aACL;EACE,GAAG;EACH,SAAS;EACT,UAAU;EACV,cAAc;EACd,iBAAiB,KAAA;CACnB,GACA,eACA,WACF;AACF"}
|
|
@@ -83,15 +83,17 @@ const useQueryErrorResetBoundary = () => (0, preact_hooks.useContext)(QueryError
|
|
|
83
83
|
* return children
|
|
84
84
|
* }
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* <
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
86
|
+
* function App() {
|
|
87
|
+
* return (
|
|
88
|
+
* <QueryErrorResetBoundary>
|
|
89
|
+
* {({ reset }) => (
|
|
90
|
+
* <ErrorBoundary reset={reset}>
|
|
91
|
+
* <Page />
|
|
92
|
+
* </ErrorBoundary>
|
|
93
|
+
* )}
|
|
94
|
+
* </QueryErrorResetBoundary>
|
|
95
|
+
* )
|
|
96
|
+
* }
|
|
95
97
|
* ```
|
|
96
98
|
*/
|
|
97
99
|
const QueryErrorResetBoundary = ({ children }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.cjs","names":["createContext","useContext","useState"],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\n reset: QueryErrorResetFunction\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = createContext(createValue())\n\n// HOOK\n\n/**\n * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary\n * defined it will reset them globally.\n *\n * @returns The boundary's {@link QueryErrorResetBoundaryValue}.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\n/**\n * A render-prop function usable as `children` on `QueryErrorResetBoundary`.\n *\n * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.\n * @returns The children to render.\n */\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\n/**\n * The props accepted by `QueryErrorResetBoundary`.\n */\nexport interface QueryErrorResetBoundaryProps {\n /**\n * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and\n * returns a node.\n */\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\n/**\n * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to\n * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can\n * reset any query errors within the boundaries of the component.\n *\n * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}\n * if `children` is a function.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n *
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.cjs","names":["createContext","useContext","useState"],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\n reset: QueryErrorResetFunction\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = createContext(createValue())\n\n// HOOK\n\n/**\n * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary\n * defined it will reset them globally.\n *\n * @returns The boundary's {@link QueryErrorResetBoundaryValue}.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\n/**\n * A render-prop function usable as `children` on `QueryErrorResetBoundary`.\n *\n * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.\n * @returns The children to render.\n */\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\n/**\n * The props accepted by `QueryErrorResetBoundary`.\n */\nexport interface QueryErrorResetBoundaryProps {\n /**\n * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and\n * returns a node.\n */\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\n/**\n * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to\n * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can\n * reset any query errors within the boundaries of the component.\n *\n * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}\n * if `children` is a function.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary reset={reset}>\n * <Page />\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;;AAoCA,SAAS,cAA4C;CACnD,IAAI,UAAU;CACd,OAAO;EACL,kBAAkB;GAChB,UAAU;EACZ;EACA,aAAa;GACX,UAAU;EACZ;EACA,eAAe;GACb,OAAO;EACT;CACF;AACF;AAEA,MAAM,kCAAA,GAAiCA,OAAAA,cAAAA,CAAc,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiClE,MAAa,oCAAA,GACXC,aAAAA,WAAAA,CAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyE3C,MAAa,2BAA2B,EACtC,eACkC;CAClC,MAAM,CAAC,UAAA,GAASC,aAAAA,SAAAA,OAAe,YAAY,CAAC;CAC5C,OACE,iBAAA,GAAA,mBAAA,IAAA,CAAC,+BAA+B,UAAhC;EAAgD;EAC7C,UAAA,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;CACb,CAAA;AAE7C"}
|
|
@@ -108,15 +108,17 @@ interface QueryErrorResetBoundaryProps {
|
|
|
108
108
|
* return children
|
|
109
109
|
* }
|
|
110
110
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* <
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
111
|
+
* function App() {
|
|
112
|
+
* return (
|
|
113
|
+
* <QueryErrorResetBoundary>
|
|
114
|
+
* {({ reset }) => (
|
|
115
|
+
* <ErrorBoundary reset={reset}>
|
|
116
|
+
* <Page />
|
|
117
|
+
* </ErrorBoundary>
|
|
118
|
+
* )}
|
|
119
|
+
* </QueryErrorResetBoundary>
|
|
120
|
+
* )
|
|
121
|
+
* }
|
|
120
122
|
* ```
|
|
121
123
|
*/
|
|
122
124
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("preact").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.cts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDjC,4BAA2B,YAErC,kDAA4B,IAAA"}
|
|
@@ -108,15 +108,17 @@ interface QueryErrorResetBoundaryProps {
|
|
|
108
108
|
* return children
|
|
109
109
|
* }
|
|
110
110
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* <
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
111
|
+
* function App() {
|
|
112
|
+
* return (
|
|
113
|
+
* <QueryErrorResetBoundary>
|
|
114
|
+
* {({ reset }) => (
|
|
115
|
+
* <ErrorBoundary reset={reset}>
|
|
116
|
+
* <Page />
|
|
117
|
+
* </ErrorBoundary>
|
|
118
|
+
* )}
|
|
119
|
+
* </QueryErrorResetBoundary>
|
|
120
|
+
* )
|
|
121
|
+
* }
|
|
120
122
|
* ```
|
|
121
123
|
*/
|
|
122
124
|
declare const QueryErrorResetBoundary: ({ children }: QueryErrorResetBoundaryProps) => import("preact").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.d.ts","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"mappings":";;;;;KASY;;;;KAKA;;;;KAKA;UAEK;;;;EAIf,YAAY;;;;EAIZ,SAAS;;;;EAIT,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDI,kCAA0B;;;;;;;KAW3B,mCACV,OAAO,iCACJ;;;;UAKY;;;;;EAKf,UAAU,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmDjC,4BAA2B,YAErC,kDAA4B,IAAA"}
|
|
@@ -82,15 +82,17 @@ const useQueryErrorResetBoundary = () => useContext(QueryErrorResetBoundaryConte
|
|
|
82
82
|
* return children
|
|
83
83
|
* }
|
|
84
84
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* <
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
85
|
+
* function App() {
|
|
86
|
+
* return (
|
|
87
|
+
* <QueryErrorResetBoundary>
|
|
88
|
+
* {({ reset }) => (
|
|
89
|
+
* <ErrorBoundary reset={reset}>
|
|
90
|
+
* <Page />
|
|
91
|
+
* </ErrorBoundary>
|
|
92
|
+
* )}
|
|
93
|
+
* </QueryErrorResetBoundary>
|
|
94
|
+
* )
|
|
95
|
+
* }
|
|
94
96
|
* ```
|
|
95
97
|
*/
|
|
96
98
|
const QueryErrorResetBoundary = ({ children }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.js","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\n reset: QueryErrorResetFunction\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = createContext(createValue())\n\n// HOOK\n\n/**\n * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary\n * defined it will reset them globally.\n *\n * @returns The boundary's {@link QueryErrorResetBoundaryValue}.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\n/**\n * A render-prop function usable as `children` on `QueryErrorResetBoundary`.\n *\n * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.\n * @returns The children to render.\n */\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\n/**\n * The props accepted by `QueryErrorResetBoundary`.\n */\nexport interface QueryErrorResetBoundaryProps {\n /**\n * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and\n * returns a node.\n */\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\n/**\n * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to\n * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can\n * reset any query errors within the boundaries of the component.\n *\n * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}\n * if `children` is a function.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n *
|
|
1
|
+
{"version":3,"file":"QueryErrorResetBoundary.js","names":[],"sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport type { ComponentChildren } from 'preact'\nimport { useContext, useState } from 'preact/hooks'\n\n// CONTEXT\n\n/**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\nexport type QueryErrorResetFunction = () => void\n\n/**\n * Returns whether the boundary has been reset and not yet cleared.\n */\nexport type QueryErrorIsResetFunction = () => boolean\n\n/**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\nexport type QueryErrorClearResetFunction = () => void\n\nexport interface QueryErrorResetBoundaryValue {\n /**\n * Clears the reset state, so queries know not to try again until the boundary is reset again.\n */\n clearReset: QueryErrorClearResetFunction\n /**\n * Returns whether the boundary has been reset and not yet cleared.\n */\n isReset: QueryErrorIsResetFunction\n /**\n * Resets any query errors within the boundary, so queries know they can try again.\n */\n reset: QueryErrorResetFunction\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = createContext(createValue())\n\n// HOOK\n\n/**\n * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary\n * defined it will reset them globally.\n *\n * @returns The boundary's {@link QueryErrorResetBoundaryValue}.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { useQueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function App({ children }: { children: ComponentChildren }) {\n * const { reset } = useQueryErrorResetBoundary()\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n * ```\n */\nexport const useQueryErrorResetBoundary = () =>\n useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\n/**\n * A render-prop function usable as `children` on `QueryErrorResetBoundary`.\n *\n * @param value - The boundary's {@link QueryErrorResetBoundaryValue}.\n * @returns The children to render.\n */\nexport type QueryErrorResetBoundaryFunction = (\n value: QueryErrorResetBoundaryValue,\n) => ComponentChildren\n\n/**\n * The props accepted by `QueryErrorResetBoundary`.\n */\nexport interface QueryErrorResetBoundaryProps {\n /**\n * Either a plain node, or a function that receives the boundary's {@link QueryErrorResetBoundaryValue} and\n * returns a node.\n */\n children: QueryErrorResetBoundaryFunction | ComponentChildren\n}\n\n/**\n * When using `suspense` or `throwOnError` in your queries, you need a way to let queries know that you want to\n * try again when re-rendering after some error occurred. With the `QueryErrorResetBoundary` component you can\n * reset any query errors within the boundaries of the component.\n *\n * @returns The `children`, rendered as-is, or called with the boundary's {@link QueryErrorResetBoundaryValue}\n * if `children` is a function.\n *\n * @example\n * ```tsx\n * import { useErrorBoundary } from 'preact/hooks'\n * import type { ComponentChildren } from 'preact'\n * import { QueryErrorResetBoundary } from '@tanstack/preact-query'\n *\n * function ErrorBoundary({\n * children,\n * reset,\n * }: {\n * children: ComponentChildren\n * reset: () => void\n * }) {\n * const [error, resetError] = useErrorBoundary(() => reset())\n *\n * if (error) {\n * return (\n * <div>\n * There was an error!\n * <button onClick={() => resetError()}>Try again</button>\n * </div>\n * )\n * }\n *\n * return children\n * }\n *\n * function App() {\n * return (\n * <QueryErrorResetBoundary>\n * {({ reset }) => (\n * <ErrorBoundary reset={reset}>\n * <Page />\n * </ErrorBoundary>\n * )}\n * </QueryErrorResetBoundary>\n * )\n * }\n * ```\n */\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function' ? children(value) : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"mappings":";;;;AAoCA,SAAS,cAA4C;CACnD,IAAI,UAAU;CACd,OAAO;EACL,kBAAkB;GAChB,UAAU;EACZ;EACA,aAAa;GACX,UAAU;EACZ;EACA,eAAe;GACb,OAAO;EACT;CACF;AACF;AAEA,MAAM,iCAAiC,cAAc,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiClE,MAAa,mCACX,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyE3C,MAAa,2BAA2B,EACtC,eACkC;CAClC,MAAM,CAAC,SAAS,eAAe,YAAY,CAAC;CAC5C,OACE,oBAAC,+BAA+B,UAAhC;EAAgD;EAC7C,UAAA,OAAO,aAAa,aAAa,SAAS,KAAK,IAAI;CACb,CAAA;AAE7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,\n * `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and\n * `isFetchingPreviousPage`.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/preact-query'\n *\n * function Projects() {\n * const { data } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,\n * `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and\n * `isFetchingPreviousPage`.\n *\n * @example\n * ```tsx\n * import {
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type {\n DefaultError,\n InfiniteData,\n QueryClient,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefinedUseInfiniteQueryResult,\n UseInfiniteQueryOptions,\n UseInfiniteQueryResult,\n} from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,\n * `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and\n * `isFetchingPreviousPage`.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/preact-query'\n *\n * function Projects() {\n * const { data } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * return <>{data.pages.map((page) => page.projects.map((p) => <p key={p.id}>{p.name}</p>))}</>\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): DefinedUseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,\n * `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and\n * `isFetchingPreviousPage`.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/preact-query'\n *\n * function Projects() {\n * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * return (\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of `queryFn`,\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @see {@link infiniteQueryOptions} to share these options between `useInfiniteQuery` and imperative APIs like `queryClient.infiniteQuery`.\n * @param options - The {@link UseInfiniteQueryOptions} to use — everything you can pass to `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The same properties as `useQuery`, with the addition of `data.pages`, `data.pageParams`,\n * `fetchNextPage`, `fetchPreviousPage`, `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and\n * `isFetchingPreviousPage`.\n *\n * @example\n * ```tsx\n * import { useInfiniteQuery } from '@tanstack/preact-query'\n *\n * function Projects() {\n * const { data, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage } =\n * useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * return (\n * <button\n * onClick={() => fetchNextPage()}\n * disabled={!hasNextPage || isFetching}\n * >\n * {isFetchingNextPage\n * ? 'Loading more...'\n * : hasNextPage\n * ? 'Load More'\n * : 'Nothing more to load'}\n * </button>\n * )\n * }\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError>\n\nexport function useInfiniteQuery(\n options: UseInfiniteQueryOptions,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n options,\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n )\n}\n"],"mappings":";;;;AA+LA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACL,SACAC,qBAAAA,uBACA,WACF;AACF"}
|