You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react/use.md
+14-16Lines changed: 14 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1540,34 +1540,32 @@ See [caching Promises for Client Components](#caching-promises-for-client-compon
1540
1540
1541
1541
---
1542
1542
1543
-
### `use` returns the value of a different Promise {/*wrong-promise-value*/}
1543
+
### I get the value of a different Promise from `use` {/*wrong-promise-value*/}
1544
1544
1545
-
On the server, React matches each `use` call to its Promise by call order, not by the Promise itself. If a component suspends and runs again, React reuses the Promise already recorded at each position.
1545
+
On the server, React matches each `use` call to its Promise by call order, not by the Promise itself. A component suspends while the Promise passed to `use` is pending, then runs again once that Promise resolves. When resuming, React reuses the Promise already recorded at each position.
1546
1546
1547
-
If `use`is called conditionally, and the condition stops `use`from being called once its Promise resolves, the next`use` call takes the skipped position and receives the earlier Promise's value:
1547
+
If `use`causes a suspend and `use`is no longer called after resuming, every later`use` call with a Promise shifts up a position. This means `use` may be passed a Promise meant for a different callsite. This happens when a component stops calling `use` once its data is cached:
1548
1548
1549
1549
```js
1550
1550
functionAlbum() {
1551
-
// 🔴 Called on the first attempt, which resolves `tracksPromise`
1552
-
//and sets `cache.tracks`. Skipped on the attempt after that.
1553
-
consttracks=cache.tracks??use(tracksPromise);
1551
+
// 🔴 First `use` is called and causes a suspend. When resuming the
1552
+
//value for `cache.tracks` is used and `use` is no longer called
0 commit comments