@@ -216,7 +216,7 @@ export const ProfileResource = createResource({
216
216
});
217
217
```
218
218
219
- ``` tsx title="ProfileList"
219
+ ``` tsx title="ProfileList" {5}
220
220
import { useSuspense } from ' @data-client/react' ;
221
221
import { ProfileResource } from ' ./ProfileResource' ;
222
222
@@ -241,18 +241,23 @@ render(<ProfileList />);
241
241
242
242
</HooksPlayground >
243
243
244
+ ### Pagination
245
+
246
+ Reactive [ pagination] ( /rest/guides/pagination ) is achieved with [ mutable schemas] ( /rest/api/Collection )
247
+
248
+ <PaginationDemo />
249
+
244
250
### Sequential
245
251
246
252
When fetch parameters depend on data from another resource.
247
253
248
254
``` tsx
249
255
function PostWithAuthor() {
250
256
const post = useSuspense (PostResource .get , { id });
251
- // post as Post
252
257
const author = useSuspense (UserResource .get , {
258
+ // highlight-next-line
253
259
id: post .userId ,
254
260
});
255
- // author as User
256
261
}
257
262
```
258
263
@@ -305,12 +310,11 @@ export const UserResource = createResource({
305
310
});
306
311
```
307
312
308
- ``` tsx title="PostWithAuthor"
313
+ ``` tsx title="PostWithAuthor" {7-11}
309
314
import { PostResource , UserResource } from ' ./Resources' ;
310
315
311
316
export default function PostWithAuthor({ id }: { id: string }) {
312
317
const post = useSuspense (PostResource .get , { id });
313
- // post as Post
314
318
const author = useSuspense (
315
319
UserResource .get ,
316
320
post .userId
@@ -332,7 +336,7 @@ When entities are stored in [nested structures](/rest/guides/relational-data#nes
332
336
333
337
<TypeScriptEditor row ={false} >
334
338
335
- ``` typescript title="api/Post"
339
+ ``` typescript title="api/Post" {15-19}
336
340
export class PaginatedPost extends Entity {
337
341
id = ' ' ;
338
342
title = ' ' ;
@@ -348,19 +352,19 @@ export const getPosts = new RestEndpoint({
348
352
path: ' /post' ,
349
353
searchParams: { page: ' ' },
350
354
schema: {
351
- results : new schema .Collection ([PaginatedPost ]),
355
+ posts : new schema .Collection ([PaginatedPost ]),
352
356
nextPage: ' ' ,
353
357
lastPage: ' ' ,
354
358
},
355
359
});
356
360
```
357
361
358
- ``` tsx title="ArticleList"
362
+ ``` tsx title="ArticleList" {5-7}
359
363
import { getPosts } from ' ./api/Post' ;
360
364
361
365
export default function ArticleList({ page }: { page: string }) {
362
366
const {
363
- results : posts,
367
+ posts,
364
368
nextPage,
365
369
lastPage,
366
370
} = useSuspense (getPosts , { page });
@@ -376,12 +380,6 @@ export default function ArticleList({ page }: { page: string }) {
376
380
377
381
</TypeScriptEditor >
378
382
379
- ### Pagination
380
-
381
- Reactive [ pagination] ( /rest/guides/pagination ) is achieved with [ mutable schemas] ( /rest/api/Collection )
382
-
383
- <PaginationDemo />
384
-
385
383
### Server Side Rendering
386
384
387
385
[ Server Side Rendering] ( ../guides/ssr.md ) to incrementally stream HTML,
@@ -398,6 +396,8 @@ continue showing the previous screen while the new data loads. Combined with
398
396
loading indicators - improving the user experience.
399
397
400
398
Click one of the names to navigate to their todos. Here long loading states are indicated by the
401
- less intrusive _ loading bar_ , like YouTube and Robinhood use.
399
+ less intrusive _ loading bar_ , like [ YouTube] ( https://youtube.com ) and [ Robinhood] ( https://robinhood.com ) use.
402
400
403
401
<StackBlitz app =" todo-app " file =" src/pages/Home/TodoList.tsx,src/pages/Home/index.tsx,src/useNavigationState.ts " height ={600} />
402
+
403
+ If you need help adding this to your own custom router, check out the [ official React guide] ( https://react.dev/reference/react/useTransition#building-a-suspense-enabled-router )
0 commit comments