Skip to content

Commit 166fd5b

Browse files
committed
Polish browser-only guidance wording
1 parent b14b97a commit 166fd5b

5 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/content/reference/react-dom/client/hydrateRoot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export default function App() {
319319
320320
This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration.
321321
322-
This approach is useful when you need different content on the server and in the browser. If a component should not render on the server at all, React Canary's [`browser`](/reference/react-dom/browser) API lets you mark it as browser-only without waiting for an Effect.
322+
Use this approach when you need to render different content on the server and in the browser. If a component should render only in the browser, call [`use(browser())`](/reference/react/use#use-browser) in Canary instead of waiting for an Effect.
323323
324324
<Pitfall>
325325

src/content/reference/react/Suspense.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ function Chat() {
23722372
23732373
The server HTML will include the loading indicator. It will be replaced by the `Chat` component on the client.
23742374
2375-
In React Canary, call [`use(browser())`](/reference/react/use#use-browser) instead of throwing an error to mark a component as browser-only.
2375+
If you're using Canary, call [`use(browser())`](/reference/react/use#use-browser) instead of throwing an error to mark a component as browser-only.
23762376
23772377
---
23782378

src/content/reference/react/apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In addition to [Hooks](/reference/react/hooks) and [Components](/reference/react
2727

2828
To read a value from a resource, use this API:
2929

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). In Canary, you can also pass it the value returned by [`browser`](/reference/react-dom/browser) to mark a component as browser-only during server rendering.
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). In Canary, [`use(browser())`](/reference/react/use#use-browser) marks a component as browser-only during server rendering.
3131
```js
3232
function MessageComponent({ messagePromise }) {
3333
const message = use(messagePromise);

src/content/reference/react/use.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ 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). 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.
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>
810

911
```js
1012
const value = use(resource);

src/content/reference/react/useLayoutEffect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ However, if you're running into this problem, you have a few different options:
734734
735735
- Replace `useLayoutEffect` with [`useEffect`.](/reference/react/useEffect) This tells React that it's okay to display the initial render result without blocking the paint (because the original HTML will become visible before your Effect runs).
736736
737-
- Alternatively, [mark your component as client-only.](/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content) This tells React to replace its content up to the closest [`<Suspense>`](/reference/react/Suspense) boundary with a loading fallback (for example, a spinner or a glimmer) during server rendering. In React Canary, use the [`browser`](/reference/react-dom/browser) API instead of throwing an error to mark the component as browser-only.
737+
- Alternatively, [mark your component as client-only.](/reference/react/Suspense#providing-a-fallback-for-server-errors-and-client-only-content) This tells React to replace its content up to the closest [`<Suspense>`](/reference/react/Suspense) boundary with a loading fallback (for example, a spinner or a glimmer) during server rendering. If you're using Canary, call [`use(browser())`](/reference/react/use#use-browser) instead of throwing an error.
738738
739739
- Alternatively, you can render a component with `useLayoutEffect` only after hydration. Keep a boolean `isMounted` state that's initialized to `false`, and set it to `true` inside a `useEffect` call. Your rendering logic can then be like `return isMounted ? <RealContent /> : <FallbackContent />`. On the server and during the hydration, the user will see `FallbackContent` which should not call `useLayoutEffect`. Then React will replace it with `RealContent` which runs on the client only and can include `useLayoutEffect` calls.
740740

0 commit comments

Comments
 (0)