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
+45-51Lines changed: 45 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,107 +236,101 @@ export default function SavedDraft() {
236
236
237
237
### Conditionally rendering in the browser {/*conditionally-rendering-in-the-browser*/}
238
238
239
-
Like other calls to [`use`](/reference/react/use), you can call `use(browser())` conditionally or inside a custom Hook. For example, a custom Hook can use initial data when it is available during server rendering, and read from IndexedDB in the browser when it isn't:
239
+
Like other calls to [`use`](/reference/react/use), you can call `use(browser())` conditionally or inside a custom Hook. For example, a custom Hook can return an initial value when it is provided, and read it from IndexedDB in the browser when it isn't:
240
240
241
-
```js {3}
242
-
functionuseDraft(draftId, initialDraft) {
243
-
if (initialDraft!==undefined) {
244
-
returninitialDraft;
241
+
```js {6}
242
+
functionuseSetting(settingId, initialValue) {
243
+
if (initialValue!==undefined) {
244
+
returninitialValue;
245
245
}
246
246
247
-
use(browser('The draft is stored in IndexedDB.'));
248
-
returnuse(readDraft(draftId));
247
+
use(browser('No initial setting was provided.'));
248
+
returnuse(readSetting(settingId));
249
249
}
250
250
```
251
251
252
-
On the server, `useDraft` returns `initialDraft` when it is provided. Otherwise, the closest Suspense boundary's fallback remains in the HTML. In the browser, `use(browser())` returns `undefined`, so the Hook continues and reads the draft from IndexedDB.
252
+
On the server, `useSetting` returns `initialValue` when it is provided. Otherwise, the closest Suspense boundary's fallback remains in the HTML. In the browser, `use(browser())` returns `undefined`, so the Hook continues and reads the setting from IndexedDB.
253
253
254
-
This example renders one draft with initial data and one stored in IndexedDB.
255
-
256
-
Click **Reload** to see the second draft's loading fallback while React reads it from IndexedDB.
254
+
In this example, the email notification setting is provided as initial data. The push notification setting is not, so click **Reload** to see its loading fallback while React reads it from IndexedDB.
0 commit comments