Query Docs
Examples
- Simple
- Basic
- Basic w/ GraphQL-Request
- Auto Refetching / Polling / Realtime (Next.js Pages Router)
- Optimistic Updates (Next.js App Router)
- Pagination (Next.js Pages Router)
- Load-More & Infinite Scroll (Next.js Pages Router)
- Infinite query with Max pages (Next.js Pages Router)
- Suspense
- Default Query Function
- Playground
- Prefetching (Next.js Pages Router)
- Star Wars (React Router)
- Rick And Morty (React Router)
- Next.js Pages
- Next.js app with prefetching
- Next.js app with streaming
- React Native
- Contacts (TanStack Router)
- Contacts (React Router)
- Offline Queries and Mutations (TanStack Router)
- Offline Queries and Mutations (React Router)
- Algolia
- Shadow DOM
- Devtools Embedded Panel
- Chat example (streaming)
- Batching
React Example: Offline Tanstack Router
import { Link, createFileRoute } from '@tanstack/react-router'
import { useQuery } from '@tanstack/react-query'
import { moviesQueries } from '../services/movies/queries'
export const Route = createFileRoute('/')({
component: List,
})
function List() {
const moviesQuery = useQuery(moviesQueries.list())
if (moviesQuery.isLoading) {
return 'Loading...'
}
if (moviesQuery.data) {
return (
<div>
<h1>Movies</h1>
<p>
Try to mock offline behavior with the button in the devtools. You can
navigate around as long as there is already data in the cache. You'll
get a refetch as soon as you go online again.
</p>
<ul>
{moviesQuery.data.movies.map((movie) => (
<li key={movie.id}>
<Link to="/$movieId" params={{ movieId: movie.id }}>
{movie.title}
</Link>
</li>
))}
</ul>
<div>
Updated at: {new Date(moviesQuery.data.ts).toLocaleTimeString()}
</div>
<div>{moviesQuery.isFetching && 'fetching...'}</div>
</div>
)
}
if (moviesQuery.isError) {
return (
<div>
<h1>Couldn't load movies!</h1>
<div>{moviesQuery.error.message}</div>
</div>
)
}
// query will be in 'idle' fetchStatus while restoring from localStorage
return null
}