Skip to content

Commit 025ee7a

Browse files
committed
Improve example
1 parent 9be6345 commit 025ee7a

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

src/content/reference/react/Suspense.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,43 @@ Fetching data inside an Effect does not activate the boundary. Suspense can't de
233233

234234
<Sandpack>
235235

236-
```js
236+
```js src/App.js hidden
237+
import { useState } from 'react';
238+
import ArtistPage from './ArtistPage.js';
239+
240+
export default function App() {
241+
const [show, setShow] = useState(false);
242+
if (show) {
243+
return (
244+
<ArtistPage
245+
artist={{
246+
id: 'the-beatles',
247+
name: 'The Beatles',
248+
}}
249+
/>
250+
);
251+
} else {
252+
return (
253+
<button onClick={() => setShow(true)}>
254+
Open The Beatles artist page
255+
</button>
256+
);
257+
}
258+
}
259+
```
260+
261+
```js src/ArtistPage.js active
237262
import { Suspense } from 'react';
238263
import EffectAlbums from './EffectAlbums.js';
239264

240-
export default function App() {
265+
export default function ArtistPage({ artist }) {
241266
return (
242-
<Suspense fallback={<Loading />}>
243-
<EffectAlbums artistId="the-beatles" />
244-
</Suspense>
267+
<>
268+
<h1>{artist.name}</h1>
269+
<Suspense fallback={<Loading />}>
270+
<EffectAlbums artistId={artist.id} />
271+
</Suspense>
272+
</>
245273
);
246274
}
247275

@@ -250,7 +278,7 @@ function Loading() {
250278
}
251279
```
252280

253-
```js src/EffectAlbums.js active
281+
```js src/EffectAlbums.js
254282
import { useState, useEffect } from 'react';
255283
import { fetchData } from './data.js';
256284

0 commit comments

Comments
 (0)