File tree 1 file changed +13
-4
lines changed
src/content/blog/2024/04/25
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -243,14 +243,23 @@ In React 19 we're introducing a new API to read resources in render: `use`.
243
243
244
244
For example, you can read a promise with ` use ` , and React will Suspend until the promise resolves:
245
245
246
- ``` js {1,6 }
246
+ ``` js {1,5 }
247
247
import {use } from ' react' ;
248
248
249
249
function Comments ({commentsPromise}) {
250
- // NOTE: this will resume the promise from the server.
251
- // It will suspend until the data is available.
250
+ // `use` will suspend until the promise resolves.
252
251
const comments = use (commentsPromise);
253
- return comments .map (comment => < p> {comment}< / p> );
252
+ return comments .map (comment => < p key= {comment .id }> {comment}< / p> );
253
+ }
254
+
255
+ function Page ({commentsPromise}) {
256
+ // When `use` suspends in Comments,
257
+ // this Suspense boundary will be shown.
258
+ return (
259
+ < Suspense fallback= {< div> Loading... < / div> }>
260
+ < Comments commentsPromise= {commentsPromise} / >
261
+ < / Suspense>
262
+ )
254
263
}
255
264
```
256
265
You can’t perform that action at this time.
0 commit comments