TanStack Query, minus the re-render.
The same query core you trust for caching, dedup and refetching, with every result field as its own signal. When data changes, one text node updates: 1 derivation where @tanstack/react-query does 8.
bun add @pyreon/query - engine
@tanstack/query-core5Re-exported, soQueryClientand friends import from here.- data change → DOM
- 5.6× faster than react-querySame core, happy-dom, one run.
- live data
- WebSocket, SSE, streams
useSubscription,useSSE,useStreamwrite into the same cache. - native
useQueryon iOS and AndroidExperimental; lowers to a nativePyreonQuery.
- 1 vs 8 field derivations when a component reading every field sees new data, against
@tanstack/react-query.BENCHMARKS.md §10 'query ⚠ happy-dom' row, overnight run, one run - 5.6× faster from a data change to the DOM, on the same query core.BENCHMARKS.md §10 query row, happy-dom: relative work, not browser time
- 0 component re-runs on a data change; React re-renders the component once.docs/src/content/docs/query.md 'Benchmark — fine-grained vs @tanstack/react-query'
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →What changes when the cache is made of signals.
One field changes, one node updates
data,error,status,isFetchingand the rest are separate signals, created only when you first read them. A background refetch flipsisFetchingwithout touching the text that shows the name.Keys that read signals
Options are a function, so
queryKey: ['user', props.userId]tracks the prop. Change it and the query refetches. No dependency array to forget.Live data, same cache
useSubscription(WebSocket, reconnect with backoff),useSSEanduseStreamhand you theQueryClient, so a push message can patch or invalidate cached data the rest of the app already reads.Declare a query oncenext release
queryOptions,infiniteQueryOptionsandmutationOptionsgive one typed definition for hooks, prefetching andclient.getQueryDatawith no generic.
Delete the three states and the race.
Three pieces of state, an effect, no cache, and a slow answer for the previous id can overwrite the current one.
import { useEffect, useState } from 'react'
type User = { id: number; name: string }
function UserName({ userId }: { userId: number }) {
const [data, setData] = useState<User>()
const [error, setError] = useState<Error>()
const [loading, setLoading] = useState(false)
useEffect(() => {
setLoading(true)
fetchUser(userId) // a slow answer for the old id can land last
.then(setData, setError)
.finally(() => setLoading(false))
}, [userId])
if (loading) return <p>Loading…</p>
if (error) return <p>{error.message}</p>
return <h1>{data?.name}</h1>
}Cached, deduplicated, retried, and refetched when userId changes. Only the <h1> text updates.
import { useQuery } from '@pyreon/query'
type User = { id: number; name: string }
function UserName(props: { userId: number }) {
const user = useQuery(() => ({
queryKey: ['user', props.userId],
queryFn: () => fetchUser(props.userId),
}))
return (
<h1>
{() => (user.isPending() ? 'Loading…' : user.error()?.message ?? user.data()?.name)}
</h1>
)
}Coming from TanStack Query (React)?
Same options, as a function. Same client.
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
type User = { id: number; name: string }
function Profile({ userId }: { userId: number }) {
const client = useQueryClient()
const user = useQuery({
queryKey: ['user', userId],
queryFn: () => fetchUser(userId),
})
const rename = useMutation({
mutationFn: saveUser,
onSuccess: () => client.invalidateQueries({ queryKey: ['user', userId] }),
})
if (user.isPending) return <p>Loading…</p>
if (user.isError) return <p>{user.error.message}</p>
return (
<button onClick={() => rename.mutate({ ...user.data, name: 'Ada' })}>
{user.data.name}
</button>
)
}Keys, queryFn, staleTime, QueryClient and invalidateQueries are TanStack's own. The changes: options are a function, results are called (user.data()), branches use <Match> instead of early returns, and invalidates replaces the onSuccess boilerplate.
import { Match, Switch } from '@pyreon/core'
import { useMutation, useQuery } from '@pyreon/query'
type User = { id: number; name: string }
function Profile(props: { userId: number }) {
const user = useQuery(() => ({
queryKey: ['user', props.userId], // reads a prop: a new id refetches
queryFn: () => fetchUser(props.userId),
}))
const rename = useMutation({
mutationFn: saveUser,
invalidates: [['user']],
})
return (
<Switch>
<Match when={() => user.isPending()}><p>Loading…</p></Match>
<Match when={() => user.isError()}><p>{() => user.error()?.message}</p></Match>
<Match when={() => user.data()}>
<button onClick={() => rename.mutate({ ...user.data()!, name: 'Ada' })}>
{() => user.data()?.name}
</button>
</Match>
</Switch>
)
}Three readers, one query.
Three boxes read three fields of one query. The counters show how often each one re-ran. Refetch, change the data, or return identical data: each box moves only when its own field does.
- reads isFetching() · true1
- reads data() · undefined1
- reads error() · null1
Counters are effect runs, read from the effects themselves. The network is an in-page mock with about 600 ms per request.
Fetching…
Same engine as TanStack Query. 5.6× less time from new data to the DOM.
Both adapters wrap the same @tanstack/query-core, so this measures what happens after the data arrives. Across components, react-query's tracked props are field-aware too and tie; the gap is inside one component.
- data change → DOMwin5.6× faster
- field derivations per changewin1 vs 8
- mountwin1.2× faster
The TanStack surface, plus live data.
useQuery,useMutation,useInfiniteQuery,useQuerieswith signal-reading options.defineQueriesnamed parallel queries in one declaration.- Suspense
useSuspenseQuery,useSuspenseInfiniteQuery,useSuspenseQueriesand aQuerySuspenseboundary. invalidateson mutationsuseMutation({ mutationFn, invalidates: [['posts']] })refetches on success without anonSuccess.- Typed reusable optionsnext release
queryOptions,infiniteQueryOptions,mutationOptions; the key carries the data type. - SSR hydration
dehydrateon the server,HydrationBoundaryon the client, no refetch on load. - Prefetch
usePrefetchQuery,usePrefetchInfiniteQuery, orclient.prefetchQueryon hover. - Realtime
useSubscriptionfor WebSocket,useSSEfor Server-Sent Events,useStreamfor SSE or NDJSON as reactive state. - Offline
@pyreon/query/persistrestores the cache before the first fetch. - Native mutations and infinite listsnext release
useMutationover an@pyreon/httpendpoint anduseInfiniteQuerylower to iOS and Android. Experimental.
Things to build with it.
Declare it once; use it in a hook, prefetch it on hover, and read or patch the cache with full types.
import { QueryClient, queryOptions, useQuery, useQueryClient } from '@pyreon/query'
import { signal } from '@pyreon/reactivity'
type User = { id: number; name: string }
// declare once...
const userQuery = (id: number) =>
queryOptions({ queryKey: ['user', id], queryFn: () => fetchUser(id), staleTime: 60_000 })
// ...use in a component (the factory runs inside the accessor, so it stays reactive)
const selected = signal(1)
function UserName() {
const user = useQuery(() => userQuery(selected()))
const client = useQueryClient()
return (
<a onMouseEnter={() => client.prefetchQuery(userQuery(selected() + 1))}>
{() => user.data()?.name}
</a>
)
}
// ...and in the client, typed without a generic
function rename(client: QueryClient, id: number, name: string) {
client.setQueryData(userQuery(id).queryKey, (u) => u && { ...u, name })
return client.getQueryData(userQuery(id).queryKey) // User | undefined
}The socket patches the cached list; every component already reading ['orders'] updates in place.
import { useQuery, useSubscription } from '@pyreon/query'
type Order = { id: string; status: string }
function Orders() {
const orders = useQuery(() => ({ queryKey: ['orders'], queryFn: fetchOrders }))
const live = useSubscription({
url: 'wss://api.example.com/ws',
onMessage: (event, client) => {
const msg = JSON.parse(event.data) as { type: string; order: Order }
if (msg.type === 'order-updated') {
client.setQueryData<Order[]>(['orders'], (list) =>
list?.map((o) => (o.id === msg.order.id ? msg.order : o)),
)
}
},
})
return (
<p>
{() => orders.data()?.length ?? 0} orders · socket {() => live.status()}
</p>
)
}The hooks, the boundaries, and the core.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- useQuery
- useQueries
- useInfiniteQuery
- defineQueries
- useSuspenseQuery
- useSuspenseQueries
- useSuspenseInfiniteQuery
- usePrefetchQuery
- usePrefetchInfiniteQuery
- useMutation
- useMutationState
- useIsMutating
- useSubscription
- useSSE
- useStream
- queryOptions
- infiniteQueryOptions
- mutationOptions
- QueryClientProvider
- useQueryClient
- HydrationBoundary
- QuerySuspense
- QueryErrorResetBoundary
- IsRestoringProvider
- useIsFetching
- QueryClient
- QueryCache
- MutationCache
- dehydrate
- hydrate
- keepPreviousData
- skipToken
- @pyreon/query/persist
- @pyreon/query/devtools
Good to know before you start.
Pass useQuery a function
useQuery(() => ({ … })), so the key can read signals and props. useMutation takes a plain object.
Don't return early on isPending()
A component runs once, so if (user.isPending()) return … pins it to the first branch. Use <Show>, <Switch>/<Match> or an accessor.
Create the QueryClient once
At module scope or app setup, not inside a component that might mount twice.
Native covers the common hooks
On iOS and Android useQuery and useStream lower today, and useMutation and useInfiniteQuery join them in the next release; QueryClient config, devtools and suspense queries stay web.
What people ask first.
Is this a fork of TanStack Query?
No. It depends on @tanstack/query-core and re-exports it. Caching, retries, dedup and invalidation are TanStack's code; the adapter turns results into signals.
The benchmark says happy-dom. Does that matter?
Yes: happy-dom is a JavaScript DOM, so the ratio and the derivation counts mean something and the absolute times do not. It is one overnight run that we wrote. Reproduce with bun run --filter=@pyreon/query bench:react-query.
Where is react-query just as good?
Across components. If one component reads only status and another only data, react-query's tracked props skip the right one too; that row is a tie in the docs. The gap is inside a single component that reads several fields.
Can I use the TanStack devtools?
Yes: <QueryDevtools /> from @pyreon/query/devtools is the TanStack panel.
Same cache. Fewer spinners spinning for nothing.
bun add @pyreon/query