Skip to content

Commit bff3403

Browse files
committed
Update "Deep Dive" in reusing-logic-with-custom-hooks.md with link to and example of the use API
1 parent 740016e commit bff3403

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,10 +1419,31 @@ Similar to a [design system,](https://uxdesign.cc/everything-you-need-to-know-ab
14191419
14201420
#### Will React provide any built-in solution for data fetching? {/*will-react-provide-any-built-in-solution-for-data-fetching*/}
14211421
1422+
Today, with the [`use`](/reference/react/use#streaming-data-from-server-to-client) API, data can be streamed from the server to the client by passing a Promise as a prop from a [Server Component](/reference/rsc/server-components) and resolving it in a [Client Component](/reference/rsc/use-client):
1423+
1424+
```js {3,6,13}
1425+
"use client";
1426+
1427+
import { use, Suspense } from "react";
1428+
1429+
function Message({ messagePromise }) {
1430+
const messageContent = use(messagePromise);
1431+
return <p>Here is the message: {messageContent}</p>;
1432+
}
1433+
1434+
export function MessageContainer({ messagePromise }) {
1435+
return (
1436+
<Suspense fallback={<p>⌛Downloading message...</p>}>
1437+
<Message messagePromise={messagePromise} />
1438+
</Suspense>
1439+
);
1440+
}
1441+
```
1442+
14221443
We're still working out the details, but we expect that in the future, you'll write data fetching like this:
14231444
14241445
```js {1,4,6}
1425-
import { use } from 'react'; // Not available yet!
1446+
import { use } from 'react';
14261447

14271448
function ShippingForm({ country }) {
14281449
const cities = use(fetch(`/api/cities?country=${country}`));

0 commit comments

Comments
 (0)