Open History to see the last commit
1# TanStack Preact 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/index.tsx` defines `defaultQueryFn`, which fetches `https://jsonplaceholder.typicode.com` plus `queryKey[0]`, and sets it as `defaultOptions.queries.queryFn` on the `QueryClient`.
8- In `src/index.tsx`, `Posts` calls `useQuery` with only `queryKey: ['/posts']`, and `Post` with only ``queryKey: [`/posts/${postId}`]`` and `enabled: !!postId`.
9- `Posts` also calls ``queryClient.getQueryData([`/posts/${post.id}`])`` to show posts that are already cached in bold green.
10β
11To run this example:
12β
13- `npm install`
14- `npm run dev`