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

README.md

14 lines826 Bytes

1# TanStack Lit Query Default Query Function Example
2​
3Sets a default `queryFn` on the `QueryClient` that builds the request URL from the query key, so each query only passes a `queryKey`.
4​
5## How it works
6​
7- `src/main.ts` defines `defaultQueryFn`, which fetches `https://jsonplaceholder.typicode.com` plus `queryKey[0]`, and sets it as `defaultOptions.queries.queryFn` on the `QueryClient` passed to a `QueryClientProvider` subclass.
8- `src/post-list.ts` calls `createQueryController` with only `queryKey: ['/posts']`, and calls ``useQueryClient().getQueryData([`/posts/${post.id}`])`` to show posts that are already cached in bold green.
9- `src/post-detail.ts` calls `createQueryController` with only ``queryKey: [`/posts/${this.postId}`]`` and `enabled: !!this.postId`.
10​
11To run this example:
12​
13- `npm install`
14- `npm run dev`