Skip to content

Commit 2217f45

Browse files
Update "Deep Dive" in reusing-logic-with-custom-hooks.md with link and example of the use API (#7767)
* Update "Deep Dive" in reusing-logic-with-custom-hooks.md with link to and example of the use API * Remove mention of Server Components when explaining the use API * Update src/content/learn/reusing-logic-with-custom-hooks.md Co-authored-by: Ricky <rickhanlonii@gmail.com> * fix: Correct which lines are highlighted in code example --------- Co-authored-by: Ricky <rickhanlonii@gmail.com>
1 parent e9efd19 commit 2217f45

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,10 +1419,29 @@ 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 read in render by passing a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to `use`:
1423+
1424+
```js {1,4,11}
1425+
import { use, Suspense } from "react";
1426+
1427+
function Message({ messagePromise }) {
1428+
const messageContent = use(messagePromise);
1429+
return <p>Here is the message: {messageContent}</p>;
1430+
}
1431+
1432+
export function MessageContainer({ messagePromise }) {
1433+
return (
1434+
<Suspense fallback={<p>⌛Downloading message...</p>}>
1435+
<Message messagePromise={messagePromise} />
1436+
</Suspense>
1437+
);
1438+
}
1439+
```
1440+
14221441
We're still working out the details, but we expect that in the future, you'll write data fetching like this:
14231442
14241443
```js {1,4,6}
1425-
import { use } from 'react'; // Not available yet!
1444+
import { use } from 'react';
14261445

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

0 commit comments

Comments
 (0)