mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
|
History
|
||
|---|---|---|
| .. | ||
| public | ||
| src | ||
| .gitignore | ||
| eslint.config.js | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
TanStack Solid 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.
How it works
src/services/posts/queries.tsdefinespostsQueries.list()andpostsQueries.detail(id)withqueryOptions, keyed by['posts', 'list']and['posts', 'detail', id].src/services/posts/api.tsfetches the posts from JSONPlaceholder.src/index.tsxpasses these options touseQueryin thePostsandPostcomponents and shows "Background Updating..." whileisFetchingistrue. TheQueryClientsets a 24-hourgcTime, so opened posts stay in the cache.- The
Postslist callsqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)to style links whose detail is already cached.
To run this example:
npm installnpm run dev