Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 0a315aa

Browse files
committed
Update browser example
1 parent 559ba1d commit 0a315aa

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

docs/docs/examples/03-browser/index.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { useState } from 'react'
1313
import { useQuery } from 'react-query'
1414

1515
export default function App() {
16-
const { data } = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
16+
const { data, refetch } = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
1717
queryKey: ['updater'],
18+
enabled: false,
1819
queryFn: async () => {
1920
const { update } = await versionCheck({
2021
owner: 'axelrindle',
@@ -27,20 +28,38 @@ export default function App() {
2728
})
2829

2930
return (
30-
<p>
31-
{data === undefined ?
32-
(
33-
<p>
34-
No update found.
35-
</p>
36-
) :
37-
(
38-
<p>
39-
<b>{data?.name}</b>
40-
</p>
41-
)
42-
}
43-
</p>
31+
<>
32+
<button onClick={() => refetch()}>
33+
Check
34+
</button>
35+
<p>
36+
{isIdle ? (
37+
<span>Hit <b>Reload</b> to check for updates.</span>
38+
) : isLoading ? (
39+
<span>Loading...</span>
40+
) : isError ? (
41+
<span>Error: {error.message}</span>
42+
) : (
43+
<>
44+
<div>
45+
{data === undefined ?
46+
(
47+
<p>
48+
No update found.
49+
</p>
50+
) :
51+
(
52+
<p>
53+
<b>{data?.name}</b>
54+
</p>
55+
)
56+
}
57+
</div>
58+
<div>{isFetching ? 'Fetching...' : null}</div>
59+
</>
60+
)}
61+
</p>
62+
</>
4463
)
4564
}
4665
```

packages/example-browser/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function App() {
1919
refetch
2020
} = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
2121
queryKey: ['updater'],
22+
enabled: false,
2223
queryFn: async () => {
2324
const { update } = await versionCheck({
2425
owner: 'axelrindle',
@@ -61,7 +62,7 @@ function App() {
6162

6263
<div className="card">
6364
{isIdle ? (
64-
'Not ready...'
65+
<span>Hit <b>Reload</b> to check for updates.</span>
6566
) : isLoading ? (
6667
<span>Loading...</span>
6768
) : isError ? (

0 commit comments

Comments
 (0)