Open History to see the last commit
1# TanStack Preact 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. The cache is persisted to `localStorage`.
4β
5## How it works
6β
7- `src/services/posts/queries.ts` defines `postsQueries.list()` and `postsQueries.detail(id)`, `queryOptions` factories keyed by `['posts', 'list']` and `['posts', 'detail', id]`.
8- In `src/index.tsx`, `Posts` and `Post` pass them to `useQuery`. `Posts` calls `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` to show posts that are already cached in bold green.
9- In `src/index.tsx`, the `QueryClient` sets `gcTime` to 24 hours, and `PersistQueryClientProvider` saves the cache with a `createAsyncStoragePersister` backed by `window.localStorage`, so visited posts load from the cache after a reload.
10β
11To run this example:
12β
13- `npm install`
14- `npm run dev`