Skip to content

Commit 1735172

Browse files
committed
Present browser as a use resource
1 parent c231048 commit 1735172

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/content/reference/react/apis.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ In addition to [Hooks](/reference/react/hooks) and [Components](/reference/react
2525

2626
*Resources* can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a context.
2727

28-
To read a value from a resource, use this API:
28+
You can pass these types of resources to [`use`](/reference/react/use):
29+
30+
* A [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to read its resolved value.
31+
* A [context](/learn/passing-data-deeply-with-context) to read its value.
32+
* <CanaryBadge /> The value returned by [`browser`](/reference/react-dom/browser) to mark a component as browser-only during server rendering.
2933

30-
* [`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
31-
* <CanaryBadge /> [`use(browser())`](/reference/react/use#use-browser) marks a component as browser-only during server rendering.
3234
```js
3335
function MessageComponent({ messagePromise }) {
3436
const message = use(messagePromise);
3537
const theme = use(ThemeContext);
3638
// ...
3739
}
40+
41+
function BrowserOnlyComponent() {
42+
use(browser());
43+
// ...
44+
}
3845
```

src/content/reference/react/use.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ title: use
44

55
<Intro>
66

7-
`use` is a React API that lets you read the value of a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
8-
9-
<Canary>You can also pass `use` the value returned by [`browser`](/reference/react-dom/browser) to mark a component as browser-only during server rendering.</Canary>
7+
`use` is a React API that lets you read the value of a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context). In Canary, you can also pass `use` the value returned by [`browser`](/reference/react-dom/browser) to mark a component as browser-only during server rendering.
108

119
```js
1210
const value = use(resource);

0 commit comments

Comments
 (0)