Skip to content

Commit

Permalink
Merge pull request #5 from thinkAmi-sandbox/feature/polling
Browse files Browse the repository at this point in the history
add examples: polling
  • Loading branch information
thinkAmi committed Sep 30, 2023
2 parents b837069 + 95bbac5 commit 9341412
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
@@ -0,0 +1,34 @@
import {useQuery} from "@tanstack/react-query";
import {DefaultApi} from "../../../../../types";
import {Clock} from "../../../../components/Clock";

const queryFn = () => new DefaultApi().fetchFishes({headers: {Prefer: 'dynamic=true'}}).then(async (response) => {
// 待ち時間を入れる
await new Promise(resolve => setTimeout(resolve, 1000))

return response.data.fishes
})

const Page = () => {
const {data} = useQuery({
queryKey: ['PollingWithDefaultSettings'],
queryFn: queryFn,
refetchInterval: 2000,
})


return (
<>
<Clock />

{data && (
<ul>
{data.map(f => <li key={f.id}>ID: {f.id} / Name: {f.name}</li>)}
</ul>
)}

</>
)
}

export default Page
@@ -0,0 +1,35 @@
import {useQuery} from "@tanstack/react-query";
import {DefaultApi} from "../../../../../types";
import {Clock} from "../../../../components/Clock";

const queryFn = () => new DefaultApi().fetchFishes({headers: {Prefer: 'dynamic=true'}}).then(async (response) => {
// 待ち時間を入れる
await new Promise(resolve => setTimeout(resolve, 1000))

return response.data.fishes
})

const Page = () => {
const {data} = useQuery({
queryKey: ['PollingWithDefaultSettings'],
queryFn: queryFn,
refetchInterval: 2000,
staleTime: 6000,
})


return (
<>
<Clock />

{data && (
<ul>
{data.map(f => <li key={f.id}>ID: {f.id} / Name: {f.name}</li>)}
</ul>
)}

</>
)
}

export default Page
5 changes: 2 additions & 3 deletions tanstack_prism_generouted_example/src/router.ts
Expand Up @@ -15,8 +15,6 @@ export type Path =
| `/create/use_state/create_and_reload`
| `/initial_load/tanstack_query`
| `/initial_load/use_state`
| `/polling/default_settings`
| `/polling/stale_time`
| `/query_key/factory/duplicate_keys/each_import`
| `/query_key/factory/duplicate_keys/merge`
| `/query_key/factory/merge_keys`
Expand All @@ -28,7 +26,8 @@ export type Path =
| `/query_key/selectable_reload`
| `/query_key/single_element/different_string`
| `/query_key/single_element/same_string`
| `/time/polling`
| `/time/polling/default_settings`
| `/time/polling/stale_time`
| `/time/stale_and_invalidate`
| `/time/stale_and_invalidate/clock_only`
| `/time/stale_time`
Expand Down

0 comments on commit 9341412

Please sign in to comment.