You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/browser.md
+140-1Lines changed: 140 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,10 +65,16 @@ During server rendering, `use(browser())` stops rendering the component and leav
65
65
66
66
### Rendering content only in the browser {/*rendering-content-only-in-the-browser*/}
67
67
68
-
Call `browser` inside `use` in a component that should only render in the browser:
68
+
Call `browser` inside `use` in a component that should only render in the browser.
69
69
70
70
You can use this instead of checking `typeofwindow`, waiting for an [`Effect`](/reference/react/useEffect) to set mounted state, or using a framework option to disable server rendering.
71
71
72
+
<Recipes titleText="Examples of browser-only content">
73
+
74
+
#### Loading a saved draft {/*loading-a-saved-draft*/}
75
+
76
+
`localStorage` is only available in the browser. This example uses it to load and save a draft.
77
+
72
78
Press **Render the page** to see the loading fallback. React then displays a draft loaded from `localStorage`.
73
79
74
80
<Sandpack>
@@ -215,6 +221,139 @@ iframe {
215
221
216
222
</Sandpack>
217
223
224
+
<Solution />
225
+
226
+
#### Detecting the user's time zone {/*detecting-the-users-time-zone*/}
227
+
228
+
The browser can detect the user's time zone. This example waits for the browser before reading it.
229
+
230
+
Press **Render the page** to see the loading fallback. React then displays the time zone detected by the browser.
231
+
232
+
<Sandpack>
233
+
234
+
```js src/App.js active
235
+
import { Suspense, use } from'react';
236
+
import { browser } from'react-dom';
237
+
238
+
functionTimeZone() {
239
+
use(browser("The user's time zone is detected in the browser."));
In a React Server Components app, `use(browser())` must be called from a Client Component. If your framework uses Server Components by default, add the [`'use client'`](/reference/rsc/use-client) directive to that file or move the call to a child Client Component:
0 commit comments