File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/content/blog/2024/04/25 Expand file tree Collapse file tree 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`.
243243
244244For example, you can read a promise with ` use ` , and React will Suspend until the promise resolves:
245245
246- ``` js {1,6 }
246+ ``` js {1,5 }
247247import {use } from ' react' ;
248248
249249function 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.
252251 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+ )
254263}
255264```
256265
You can’t perform that action at this time.
0 commit comments