mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| public | ||
| src | ||
| .gitignore | ||
| eslint.config.js | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
TanStack React Query Default Query Function Example
Sets a default queryFn on the QueryClient that builds the request URL from the query key, so each query only passes a queryKey.
How it works
src/index.tsxdefinesdefaultQueryFn, which fetcheshttps://jsonplaceholder.typicode.com${queryKey[0]}, and registers it asdefaultOptions.queries.queryFnon theQueryClient.- In
src/index.tsx,PostscallsuseQuery<Array<Post>>({ queryKey: ['/posts'] })andPostcallsuseQuery<Post>({ queryKey: [`/posts/${postId}`], enabled: !!postId }), without aqueryFn. - In
src/index.tsx, the list marks a post as visited whenqueryClient.getQueryData([`/posts/${post.id}`])returns cached data.
To run this example:
npm installnpm run dev