Skip to content
@pyreon/query
fundamentals · data fetching

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
Documentation
engine
@tanstack/query-core 5Re-exported, so QueryClient and friends import from here.
data change → DOM
5.6× faster than react-querySame core, happy-dom, one run.
live data
WebSocket, SSE, streamsuseSubscription, useSSE, useStream write into the same cache.
native
useQuery on iOS and AndroidExperimental; lowers to a native PyreonQuery.
A query refetches; only the field that changed updates Schematic: a cached query for ['user', 7] goes stale, refetches from the server, and the new name flows to the one reader of data().name. The isFetching reader blinks while loading; the error reader never runs. USEQUERY · ONE CACHE · THREE READERS server GET /users/7 window focus ['user', 7] fresh stale fetching staleTime: 30s dedupes · retries data().name Ada Ada L. isFetching() false true error() null never re-runs each reader subscribes to one field · the component body never re-runs
  • 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 →
why teams pick it

What changes when the cache is made of signals.

  1. One field changes, one node updates

    data, error, status, isFetching and the rest are separate signals, created only when you first read them. A background refetch flips isFetching without touching the text that shows the name.

  2. 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.

  3. Live data, same cache

    useSubscription (WebSocket, reconnect with backoff), useSSE and useStream hand you the QueryClient, so a push message can patch or invalidate cached data the rest of the app already reads.

  4. Declare a query oncenext release

    queryOptions, infiniteQueryOptions and mutationOptions give one typed definition for hooks, prefetching and client.getQueryData with no generic.

the difference

Delete the three states and the race.

React, fetching by hand

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>
}
with @pyreon/query

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

Coming from TanStack Query (React)?

Same options, as a function. Same client.

TanStack Query (React)
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>
  )
}
Pyreon

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>
  )
}
try it

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…

benchmarks

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.

vs @tanstack/react-query 5.105 on the same query core · happy-domPyreonrival · lower is better
  • data change → DOM
    win5.6× faster
  • field derivations per change
    win1 vs 8
  • mount
    win1.2× faster
Apple M3 Max · record of 2026-11-05 · overnight run, one run, happy-dom (relative work, not browser time) · author-run, syntheticFull method, every loss →
what's included

The TanStack surface, plus live data.

  • useQuery, useMutation, useInfiniteQuery, useQueries with signal-reading options.
  • defineQueries named parallel queries in one declaration.
  • Suspense useSuspenseQuery, useSuspenseInfiniteQuery, useSuspenseQueries and a QuerySuspense boundary.
  • invalidates on mutations useMutation({ mutationFn, invalidates: [['posts']] }) refetches on success without an onSuccess.
  • Typed reusable optionsnext release queryOptions, infiniteQueryOptions, mutationOptions; the key carries the data type.
  • SSR hydration dehydrate on the server, HydrationBoundary on the client, no refetch on load.
  • Prefetch usePrefetchQuery, usePrefetchInfiniteQuery, or client.prefetchQuery on hover.
  • Realtime useSubscription for WebSocket, useSSE for Server-Sent Events, useStream for SSE or NDJSON as reactive state.
  • Offline @pyreon/query/persist restores the cache before the first fetch.
  • Native mutations and infinite listsnext release useMutation over an @pyreon/http endpoint and useInfiniteQuery lower to iOS and Android. Experimental.
recipes

Things to build with it.

next release
One query definition, used everywhere

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
}
Orders that update from a WebSocket

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>
  )
}
api

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.

queries · 9
  • useQuery
  • useQueries
  • useInfiniteQuery
  • defineQueries
  • useSuspenseQuery
  • useSuspenseQueries
  • useSuspenseInfiniteQuery
  • usePrefetchQuery
  • usePrefetchInfiniteQuery
mutations · 3
  • useMutation
  • useMutationState
  • useIsMutating
live data · 3
  • useSubscription
  • useSSE
  • useStream
definitions (next release) · 3
  • queryOptions
  • infiniteQueryOptions
  • mutationOptions
providers and boundaries · 7
  • QueryClientProvider
  • useQueryClient
  • HydrationBoundary
  • QuerySuspense
  • QueryErrorResetBoundary
  • IsRestoringProvider
  • useIsFetching
core re-exports · 7
  • QueryClient
  • QueryCache
  • MutationCache
  • dehydrate
  • hydrate
  • keepPreviousData
  • skipToken
subpaths · 2
  • @pyreon/query/persist
  • @pyreon/query/devtools
good to know

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.

questions

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
Read the data-fetching guide