Skip to content

Commit 9247c01

Browse files
committed
Move browser query hook into its own example file
1 parent 9a97f41 commit 9247c01

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/content/reference/react-dom/browser.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,8 @@ Click **Reload** to see the second product's loading fallback before its query r
265265
<Sandpack>
266266
267267
```js src/App.js active
268-
import { Suspense, use } from 'react';
269-
import { browser } from 'react-dom';
270-
import { useQuery } from './query.js';
271-
272-
function useBrowserQuery(query, options) {
273-
if (options.initialData === undefined) {
274-
use(browser('useBrowserQuery: No initial data was provided.'));
275-
}
276-
return useQuery(query, options);
277-
}
268+
import { Suspense } from 'react';
269+
import { useBrowserQuery } from './useBrowserQuery.js';
278270

279271
function ProductDetails({productId, initialData}) {
280272
const product = useBrowserQuery(`/api/products/${productId}`, {
@@ -305,6 +297,19 @@ export default function App() {
305297
}
306298
```
307299
300+
```js src/useBrowserQuery.js
301+
import { use } from 'react';
302+
import { browser } from 'react-dom';
303+
import { useQuery } from './query.js';
304+
305+
export function useBrowserQuery(query, options) {
306+
if (options.initialData === undefined) {
307+
use(browser('useBrowserQuery: No initial data was provided.'));
308+
}
309+
return useQuery(query, options);
310+
}
311+
```
312+
308313
```js src/query.js hidden
309314
import { use } from 'react';
310315

0 commit comments

Comments
 (0)