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 Basic Example
A list of posts and a post detail view. Posts you have already opened are marked as visited from the query cache. The cache is persisted to localStorage.
How it works
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(id)withqueryOptions, keyed under['posts'].src/services/posts/api.tsfetches the posts from JSONPlaceholder.src/index.tsxrendersPostswithuseQuery(postsQueries.list())andPostwithuseQuery(postsQueries.detail(postId)). Both show "Background Updating..." whileisFetchingistrue.- In
src/index.tsx, the list marks a post as visited whenqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)returns cached data. src/index.tsxwraps the app inPersistQueryClientProviderwith acreateAsyncStoragePersisteroverwindow.localStorage, and itsQueryClientsetsgcTimeto 24 hours so the persisted queries are kept.
To run this example:
npm installnpm run dev