packages/octane-query
| Name | Last commit message | Last commit date |
|---|---|---|
| .. | ||
README.md
TanStack Query for Octane#
Official Octane bindings for TanStack Query.
The package reuses @tanstack/query-core and exposes the same query, mutation,
suspense, hydration, and error-reset primitives as the React adapter through
Octane hooks and components. It requires Octane 0.1.13 or newer.
import {
QueryClient,
QueryClientProvider,
useQuery,
} from '@tanstack/octane-query'
const queryClient = new QueryClient()
function Todos() @{
const query = useQuery({
queryKey: ['todos'],
queryFn: fetchTodos,
})
@if (query.isPending) {
<span>{'Loading'}</span>
} @else if (query.isError) {
<span>{query.error.message}</span>
} @else {
<ul>{query.data as unknown}</ul>
}
}
function App() @{
<QueryClientProvider client={queryClient}>
<Todos />
</QueryClientProvider>
}
API coverage#
- Queries:
useQuery,useInfiniteQuery,useSuspenseQuery,useSuspenseInfiniteQuery,useQueries,useSuspenseQueries,usePrefetchQuery, andusePrefetchInfiniteQuery - Mutations and status:
useMutation,useMutationState,useIsFetching, anduseIsMutating - Context and boundaries:
QueryClientProvider,useQueryClient,QueryClientContext,HydrationBoundary,IsRestoringProvider,useIsRestoring,QueryErrorResetBoundary, anduseQueryErrorResetBoundary - Query Core: every export from
@tanstack/query-core, includingQueryClient,dehydrate, andhydrate
The separate React companion packages, including React Query Devtools and
@tanstack/react-query-persist-client, are not part of this adapter.
Suspense, errors, and hydration#
Suspense hooks integrate with Octane's use(thenable) semantics. Catch pending
and error states with Octane's Suspense and ErrorBoundary components or its
@pending and @catch directives. Use QueryErrorResetBoundary or
useQueryErrorResetBoundary when a retry must reset a failed query.
For server rendering, create a QueryClient per request. The adapter re-exports
Query Core's dehydrate and hydrate, and HydrationBoundary also accepts
streamed dehydrated queries. IsRestoringProvider can pause fetching while a
persisted cache is restored.
The package publishes TSRX source so the Octane compiler can produce the correct client and server output. Its manifest marks the binding hooks as manually slotted; consumers should use the standard Octane Vite integration. It is a compiler-source package, not a direct Node.js runtime entry point.