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
{{ message }}
Repository navigation
Commit 262b84a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/browser.md
+63-62Lines changed: 63 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,109 +236,110 @@ 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, you can wrap a Suspense-enabled data-fetching library's `useQuery` and skip server rendering when initial data is missing:
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:
240
240
241
241
```js {3}
242
-
functionuseBrowserQuery(query, options) {
243
-
if (options.initialData===undefined) {
244
-
use(browser('useBrowserQuery: No initial data was provided.'));
use(browser('The draft is stored in IndexedDB.'));
248
+
returnuse(readDraft(draftId));
256
249
}
257
250
```
258
251
259
-
On the server, `useBrowserQuery` calls `useQuery` only when `initialData` is available. Otherwise, the closest Suspense boundary's fallback remains in the HTML. In the browser, `use(browser())` returns `undefined`, so the query library can fetch the data or read it from its client cache.
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.
260
253
261
-
This example renders one query with initial data and one without it.
254
+
This example renders one draft with initial data and one stored in IndexedDB.
262
255
263
-
Click **Reload** to see the second product's loading fallback before its query resolves.
256
+
Click **Reload** to see the second draft's loading fallback while React reads it from IndexedDB.
0 commit comments