Skip to content

Commit

Permalink
Update browser example
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Jul 4, 2023
1 parent 559ba1d commit 0a315aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
49 changes: 34 additions & 15 deletions docs/docs/examples/03-browser/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { useState } from 'react'
import { useQuery } from 'react-query'

export default function App() {
const { data } = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
const { data, refetch } = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
queryKey: ['updater'],
enabled: false,
queryFn: async () => {
const { update } = await versionCheck({
owner: 'axelrindle',
Expand All @@ -27,20 +28,38 @@ export default function App() {
})

return (
<p>
{data === undefined ?
(
<p>
No update found.
</p>
) :
(
<p>
<b>{data?.name}</b>
</p>
)
}
</p>
<>
<button onClick={() => refetch()}>
Check
</button>
<p>
{isIdle ? (
<span>Hit <b>Reload</b> to check for updates.</span>
) : isLoading ? (
<span>Loading...</span>
) : isError ? (
<span>Error: {error.message}</span>
) : (
<>
<div>
{data === undefined ?
(
<p>
No update found.
</p>
) :
(
<p>
<b>{data?.name}</b>
</p>
)
}
</div>
<div>{isFetching ? 'Fetching...' : null}</div>
</>
)}
</p>
</>
)
}
```
3 changes: 2 additions & 1 deletion packages/example-browser/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function App() {
refetch
} = useQuery<CheckResult['update'], any, CheckResult['update'], any>({
queryKey: ['updater'],
enabled: false,
queryFn: async () => {
const { update } = await versionCheck({
owner: 'axelrindle',
Expand Down Expand Up @@ -61,7 +62,7 @@ function App() {

<div className="card">
{isIdle ? (
'Not ready...'
<span>Hit <b>Reload</b> to check for updates.</span>
) : isLoading ? (
<span>Loading...</span>
) : isError ? (
Expand Down

0 comments on commit 0a315aa

Please sign in to comment.