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

README.md

15 lines841 Bytes

1# TanStack Solid Query Basic Example
2​
3A list of posts and a post detail view. Posts you have already opened are marked as visited from the query cache.
4​
5## How it works
6​
7- `src/services/posts/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(id)` with `queryOptions`, keyed by `['posts', 'list']` and `['posts', 'detail', id]`.
8- `src/services/posts/api.ts` fetches the posts from JSONPlaceholder.
9- `src/index.tsx` passes these options to `useQuery` in the `Posts` and `Post` components and shows "Background Updating..." while `isFetching` is `true`. The `QueryClient` sets a 24-hour `gcTime`, so opened posts stay in the cache.
10- The `Posts` list calls `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` to style links whose detail is already cached.
11​
12To run this example:
13​
14- `npm install`
15- `npm run dev`