Skip to content

Commit a48d506

Browse files
Align the cache with the examples above
1 parent d191c36 commit a48d506

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • src/content/reference/react

‎src/content/reference/react/use.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,12 +1548,15 @@ If `use` causes a suspend and `use` is no longer called after resuming, every la
15481548
15491549
```js
15501550
function Album() {
1551+
const tracksPromise = fetchData('/tracks');
1552+
const promiseStatus = tracksPromise.status === 'fulfilled';
1553+
15511554
// 🔴 First `use` is called and causes a suspend. When resuming the
1552-
// value for `cache.tracks` is used and `use` is no longer called
1553-
const tracks = cache.tracks ?? use(fetchData('/tracks'));
1555+
// Promise is settled and `use` is no longer called
1556+
const tracks = promiseStatus ? tracksPromise.value : use(tracksPromise);
15541557

15551558
// Now the first `use(Promise)` call, so the Promise for the first
1556-
// position (`fetchData('/tracks')`) is passed to it
1559+
// position (`tracksPromise`) is passed to it
15571560
const artist = use(fetchData('/artist'));
15581561
}
15591562
```

0 commit comments

Comments
 (0)