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
- React Router
- Offline Queries and Mutations
- Algolia
- Shadow DOM
- Devtools Embedded Panel
- Chat example (streaming)
- Batching
React Example: Devtools Panel GitHub
import React from 'react'
import ReactDOM from 'react-dom/client'
import {
QueryClient,
QueryClientProvider,
useQuery,
} from '@tanstack/react-query'
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
import { reposQueries } from './services/repos/queries'
const queryClient = new QueryClient()
export default function App() {
const [isOpen, setIsOpen] = React.useState(false)
return (
<QueryClientProvider client={queryClient}>
<Example />
<button
onClick={() => setIsOpen(!isOpen)}
>{`${isOpen ? 'Close' : 'Open'} the devtools panel`}</button>
{isOpen && <ReactQueryDevtoolsPanel onClose={() => setIsOpen(false)} />}
</QueryClientProvider>
)
}
function Example() {
const { isPending, error, data, isFetching } = useQuery(reposQueries.detail())
if (isPending) return 'Loading...'
if (error) return 'An error has occurred: ' + error.message
return (
<div
style={{
paddingBottom: 20,
}}
>
<h1>{data.full_name}</h1>
<p>{data.description}</p>
<strong>👀 {data.subscribers_count}</strong>{' '}
<strong>✨ {data.stargazers_count}</strong>{' '}
<strong>🍴 {data.forks_count}</strong>
<div>{isFetching ? 'Updating...' : ''}</div>
</div>
)
}
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)