examples/preact/basic
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Preact 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),queryOptionsfactories keyed by['posts', 'list']and['posts', 'detail', id].- In
src/index.tsx,PostsandPostpass them touseQuery.PostscallsqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)to show posts that are already cached in bold green. - In
src/index.tsx, theQueryClientsetsgcTimeto 24 hours, andPersistQueryClientProvidersaves the cache with acreateAsyncStoragePersisterbacked bywindow.localStorage, so visited posts load from the cache after a reload.
To run this example:
npm installnpm run dev