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

@api-hooks/pub

v1.0.0

Published

React hooks for the pub.dev REST API, built on @tanstack/react-query

Readme

@api-hooks/pub

React hooks for the pub.dev REST API, built on pub-api-client and @tanstack/react-query.

npm npm downloads CI License: MIT TypeScript

Requirements

| Peer dependency | Version | | --------------- | ------- | | react | >=19.0.0 | | @tanstack/react-query | ^5.0.0 |

Installation

npm install @api-hooks/pub @tanstack/react-query

Setup

Wrap your application with a QueryClientProvider and a PubClientProvider once at the root:

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { PubClientProvider } from '@api-hooks/pub';

const queryClient = new QueryClient();

export default function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <PubClientProvider>
        <YourApp />
      </PubClientProvider>
    </QueryClientProvider>
  );
}

By default, requests go to pub.dev. To point at a private/mirrored pub registry, pass baseUrl through PubClientProvider:

<PubClientProvider options={{ baseUrl: 'https://my-pub-mirror.example.com' }}>
  <YourApp />
</PubClientProvider>

PubClientProvider is optional — hooks fall back to a default PubClient (pointed at pub.dev) when no provider is present.

Hooks

Query hooks return a UseQueryResult — you get the full TanStack Query API: data, isLoading, isFetching, isError, error, refetch, and more. usePubSearchInfinite returns a UseInfiniteQueryResult.

| Hook | Description | Returns | | ---- | ----------- | ------- | | usePubPackageInfo(name, options?) | Full package info: latest + all versions | PubPackageInfo | | usePubPackageVersions(name, options?) | All published versions of a package | PubVersionInfo[] | | usePubPackageVersion(name, version, options?) | Metadata for a specific version | PubVersionInfo | | usePubPackageLatest(name, options?) | Metadata for the latest version | PubVersionInfo | | usePubPackageScore(name, options?) | Pub points, likes, popularity score | PubPackageScore | | usePubSearch(params?, options?) | Search pub.dev packages | PubSearchResult | | usePubSearchInfinite(options?) | Infinite-scroll variant of usePubSearch | InfiniteData<PubSearchResult> |


API Reference

usePubPackageInfo(name, options?)

Fetches full pub.dev package info, including latest version and all published versions.

import { usePubPackageInfo } from '@api-hooks/pub';

function PackageDetail() {
  const { data } = usePubPackageInfo('http');

  return <p>Latest: {data?.latest.version}</p>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query (also disabled when name is empty) | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubPackageVersions(name, options?)

Fetches all published versions of a pub.dev package.

import { usePubPackageVersions } from '@api-hooks/pub';

function VersionList() {
  const { data } = usePubPackageVersions('http');

  return <ul>{data?.map(v => <li key={v.version}>{v.version}</li>)}</ul>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query (also disabled when name is empty) | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubPackageVersion(name, version, options?)

Fetches metadata for a specific published version of a pub.dev package.

import { usePubPackageVersion } from '@api-hooks/pub';

function VersionDetail() {
  const { data } = usePubPackageVersion('http', '1.2.2');

  return <p>Published: {data?.published}</p>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query (also disabled when name or version is empty) | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubPackageLatest(name, options?)

Fetches metadata for the latest published version of a pub.dev package.

import { usePubPackageLatest } from '@api-hooks/pub';

function LatestVersion() {
  const { data } = usePubPackageLatest('http');

  return <p>Latest: {data?.version}</p>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query (also disabled when name is empty) | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubPackageScore(name, options?)

Fetches pub points, likes, and popularity score for a package.

import { usePubPackageScore } from '@api-hooks/pub';

function ScoreBadge() {
  const { data } = usePubPackageScore('http');

  return <p>{data?.grantedPoints} / {data?.maxPoints} pub points</p>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query (also disabled when name is empty) | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubSearch(params?, options?)

Searches pub.dev packages by text.

import { usePubSearch } from '@api-hooks/pub';

function PackageSearch() {
  const { data, isLoading } = usePubSearch({ query: 'http client' });

  if (isLoading) return <p>Loading…</p>;

  return <ul>{data?.packages.map(p => <li key={p.package}>{p.package}</li>)}</ul>;
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | enabled | boolean | true | Disable the query | | queryOptions | QueryOverrides<TData> | undefined | Override TanStack Query options (staleTime, retry, gcTime, select, etc.) |


usePubSearchInfinite(options?)

Infinite-scroll variant of usePubSearch. Each page advances the 1-based page number; continues while lastPage.next is present. Call fetchNextPage() to load the next batch — results accumulate in data.pages.

import { usePubSearchInfinite } from '@api-hooks/pub';

function PackageSearchInfinite() {
  const { data, fetchNextPage, hasNextPage } = usePubSearchInfinite({ query: 'json' });

  return (
    <>
      {data?.pages.flatMap(page => page.packages).map(p => (
        <div key={p.package}>{p.package}</div>
      ))}
      {hasNextPage && <button onClick={() => fetchNextPage()}>Load more</button>}
    </>
  );
}

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | query | string | undefined | Search text | | enabled | boolean | true | Disable the query | | queryOptions | InfiniteQueryOverrides<TData> | undefined | Override TanStack Query options |


License

MIT © ElJijuna