npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cogs/react-query

v0.2.0

Published

The single TanStack Query seam — re-exports the library plus a shared createQueryClient (centralised retry, 401/403 handling) and stable object-key hashing for Kubb-generated hooks

Readme

@cogs/react-query

The single TanStack Query seam. It re-exports the whole of @tanstack/react-query, plus a shared createQueryClient and stable key hashing, so every Kubb-generated hook and every app call site imports Query from one place — one library version, one QueryClient, one retry/auth policy.

Why a seam

Point Kubb's React Query plugin at this package instead of @tanstack/react-query:

// kubb.config.ts
pluginReactQuery({
  query: { importPath: '@cogs/react-query' },
  mutation: { importPath: '@cogs/react-query' },
  client: { importPath: '@cogs/fetch-client' },
})

Generated hooks then import useQuery/useMutation/queryOptions from here. Bump the Query major in one package.json; every generated client moves together. No two copies of the library fighting over one cache.

createQueryClient

import { QueryClientProvider } from '@cogs/react-query'
import { createQueryClient } from '@cogs/react-query'

const client = createQueryClient({
  onUnauthorized: () => router.push('/login'),
  onForbidden: () => toast.error('Not allowed'),
})

<QueryClientProvider client={client}>{children}</QueryClientProvider>

Centralised policy, identical everywhere:

  • Retry — up to 3 by default, but never on a terminal 4xx. 408 (timeout) and 429 (rate limit) are still retried; every other 4xx is not.
  • Mutations never retry by default — replaying a non-idempotent write risks a duplicate. Opt in per mutation.
  • 401 → onUnauthorized, 403 → onForbidden, everything else → onError. Status is read off the error the transport threw (@cogs/fetch-client puts it on .status).

hashKey

hashKey / hashKeys stringify a query key with object properties sorted, so Kubb's object-shaped keys ([{ url, id }]) hash identically regardless of property order — two structurally-equal keys never split into two cache entries.

Cache determinism helpers

bumpUpdatedAt, cancelAndSnapshot, and rollback centralise the cancel-in-flight / optimistic-write / rollback-on-error pattern so mutation hooks don't hand-roll it per call site. See the react-query-cache-determinism skill for the full pattern (deep-merge vs replace, invalidation strategy).

import { cancelAndSnapshot, rollback, bumpUpdatedAt, useMutation } from '@cogs/react-query'
import type { QueryClient } from '@cogs/react-query'

function useUpdateRecord(queryClient: QueryClient, id: string) {
  const detailKey = ['record', id]
  const listKey = ['records']

  return useMutation({
    mutationFn: updateRecord,
    onMutate: () =>
      // Cancel in-flight fetches and snapshot current data for rollback.
      cancelAndSnapshot(queryClient, [detailKey, listKey]),
    onSuccess: (data) => {
      // Monotonic updatedAt: two same-millisecond writes never tie.
      queryClient.setQueryData(detailKey, data, {
        updatedAt: bumpUpdatedAt(queryClient, detailKey),
      })
    },
    onError: (_err, _vars, snapshot) => {
      if (snapshot) rollback(queryClient, snapshot)
    },
  })
}

cancelAndSnapshot cancels in-flight queries for the given keys and returns a snapshot of their cached data; rollback restores it — removing an entry that had no prior data instead of writing it back as undefined, since setQueryData treats undefined as a no-op.

nextHashKeys

nextHashKeys / nextHashKey / nextHashMergedKeys tag a query key for Next.js's fetch() next.tags cache-invalidation API. This is a distinct algorithm from hashKey/hashKeys above (which hash a whole key for devtools prefix comparison): nextHashKeys hashes each key segment independently. Wire it into a generated query function:

config.next = { tags: nextHashKeys(queryKey) }

so a mutation's revalidateTag() call can target exactly the query keys it affects.

Devtools

import { ReactQueryDevtools } from '@cogs/react-query/devtools'