Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

extra.tsrx

19 lines674 Bytes

1import { QueryClientProvider, useQuery } from '@tanstack/octane-query';
2​
3// queryKey derived from a prop β€” changing the prop swaps the query (exercises
4// observer.setOptions β†’ query change β†’ refetch β†’ re-render).
5export function KeyedReader(props: { k: number }) @{
6 const q = useQuery({
7 queryKey: ['keyed', props.k],
8 queryFn: () => Promise.resolve('v' + props.k),
9 retry: false,
10 staleTime: Infinity,
11 });
12 <div id="status">{(q.isPending ? 'pending' : 'data:' + q.data) as string}</div>
14​
15export function KeyedApp(props: { client: unknown; k: number }) @{
16 <QueryClientProvider client={props.client}>
17 <KeyedReader k={props.k} />
18 </QueryClientProvider>