Skip to content

Commit 5297a68

Browse files
committed
docs: Add vue examples for suspense page
1 parent 52a8979 commit 5297a68

File tree

13 files changed

+1255
-76
lines changed

13 files changed

+1255
-76
lines changed

docs/core/api/useSuspense.md

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ description: High performance async data rendering without overfetching. useSusp
1111
import Tabs from '@theme/Tabs';
1212
import TabItem from '@theme/TabItem';
1313
import GenericsTabs from '@site/src/components/GenericsTabs';
14-
import FrameworkTabs, { TabItem as FrameworkTabItem } from '@site/src/components/FrameworkTabs';
1514
import ConditionalDependencies from '../shared/\_conditional_dependencies.mdx';
1615
import PaginationDemo from '../shared/\_pagination.mdx';
1716
import HooksPlayground from '@site/src/components/HooksPlayground';
@@ -42,9 +41,6 @@ values={[
4241
]}>
4342
<TabItem value="rest">
4443

45-
<FrameworkTabs>
46-
<FrameworkTabItem value="react">
47-
4844
<HooksPlayground fixtures={detailFixtures} row>
4945

5046
```typescript title="ProfileResource" collapsed
@@ -86,53 +82,6 @@ render(<ProfileDetail />);
8682

8783
</HooksPlayground>
8884

89-
</FrameworkTabItem>
90-
<FrameworkTabItem value="vue">
91-
92-
<TypeScriptEditor>
93-
94-
```typescript title="ProfileResource" collapsed
95-
import { Entity, resource } from '@data-client/rest';
96-
97-
export class Profile extends Entity {
98-
id: number | undefined = undefined;
99-
avatar = '';
100-
fullName = '';
101-
bio = '';
102-
103-
static key = 'Profile';
104-
}
105-
106-
export const ProfileResource = resource({
107-
path: '/profiles/:id',
108-
schema: Profile,
109-
});
110-
```
111-
112-
```html title="ProfileDetail.vue"
113-
<script setup lang="ts">
114-
import { useSuspense } from '@data-client/vue';
115-
import { ProfileResource } from './ProfileResource';
116-
117-
const profile = await useSuspense(ProfileResource.get, { id: 1 });
118-
</script>
119-
120-
<template>
121-
<div class="listItem">
122-
<Avatar :src="profile.avatar" />
123-
<div>
124-
<h4>{{ profile.fullName }}</h4>
125-
<p>{{ profile.bio }}</p>
126-
</div>
127-
</div>
128-
</template>
129-
```
130-
131-
</TypeScriptEditor>
132-
133-
</FrameworkTabItem>
134-
</FrameworkTabs>
135-
13685
</TabItem>
13786
<TabItem value="other">
13887

@@ -185,12 +134,12 @@ render(<ProfileDetail />);
185134

186135
Cache policy is [Stale-While-Revalidate](https://tools.ietf.org/html/rfc5861) by default but also [configurable](../concepts/expiry-policy.md).
187136

188-
| Expiry Status | Fetch | Suspend | Error | Conditions |
189-
| ------------- | --------------- | ------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
137+
| Expiry Status | Fetch | Suspend | Error | Conditions |
138+
| ------------- | --------------- | ------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
190139
| Invalid | yes<sup>1</sup> | yes | no | not in store, [deletion](/rest/api/resource#delete), [invalidation](./Controller.md#invalidate), [invalidIfStale](../concepts/expiry-policy.md#endpointinvalidifstale) |
191-
| Stale | yes<sup>1</sup> | no | no | (first-render, arg change) & [expiry &lt; now](../concepts/expiry-policy.md) |
192-
| Valid | no | no | maybe<sup>2</sup> | fetch completion |
193-
| | no | no | no | `null` used as second argument |
140+
| Stale | yes<sup>1</sup> | no | no | (first-render, arg change) & [expiry &lt; now](../concepts/expiry-policy.md) |
141+
| Valid | no | no | maybe<sup>2</sup> | fetch completion |
142+
| | no | no | no | `null` used as second argument |
194143

195144
:::note
196145

@@ -399,11 +348,7 @@ export const getPosts = new RestEndpoint({
399348
import { getPosts } from './api/Post';
400349

401350
export default function ArticleList({ page }: { page: string }) {
402-
const {
403-
posts,
404-
nextPage,
405-
lastPage,
406-
} = useSuspense(getPosts, { page });
351+
const { posts, nextPage, lastPage } = useSuspense(getPosts, { page });
407352
return (
408353
<div>
409354
{posts.map(post => (
@@ -439,4 +384,4 @@ less intrusive _loading bar_, like [YouTube](https://youtube.com) and [Robinhood
439384

440385
<StackBlitz app="todo-app" file="src/pages/Home/TodoList.tsx,src/pages/Home/index.tsx,src/useNavigationState.ts" height={600} />
441386

442-
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)
387+
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

Comments
 (0)