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

use-param-sync

v1.1.0

Published

DX-first React hooks for URL query state + latest-wins async fetching.

Downloads

282

Readme

use-param-sync

npm license peer

Type-safe URL query state and latest-wins async for React 18+ — small surface area, no extra runtime beyond React, ESM + CJS, full TypeScript types.

🌐 Landing page & live demo: https://use-sync-param.vercel.app/

📦 npm: https://www.npmjs.com/package/use-param-sync


Why this exists

Most libraries optimize for either keeping UI state in the URL or making async effects safe when inputs change. This one does both with two hooks that compose naturally: drive fetches from URL-backed filters without race conditions or stale responses.


Features

| | | | ---------------- | ------------------------------------------------------------------------------------------------------------------- | | URL sync | React state ↔ query string (pushState / replaceState, no full reload) | | Navigation | popstate (back/forward) updates state | | Debouncing | Optional debounce on history writes only; UI state stays snappy | | Types | Inferred state from initialState; supports string, number, boolean, string[] (comma-separated in the URL) | | Async safety | AbortController + ignore stale results; pass AbortSignal when your function accepts it | | Bundle | sideEffects: false, tree-shakable exports |


Installation

npm install use-param-sync
pnpm add use-param-sync
yarn add use-param-sync

Peer dependency: react >= 18.


Live Demo

Explore real-world examples with URL state syncing, async cancellation, Axios integration, mutations, and large filter models:

👉 https://use-sync-param.vercel.app/demo

Quick start

useUrlState

Keeps selected keys in sync with the query string. Arrays are serialized as comma-separated values (e.g. tags=react,js).

const [filters, setFilters] = useUrlState({
  search: "",
  page: 1,
  tags: [] as string[],
});

// Example URL:
// ?search=react&page=2&tags=react,js
useUrlState(initialState, {
  debounce: 300, // ms; debounces history updates, not React setState
  history: "replace", // "replace" | "push"
});

useLatestAsync

Runs when deps change; aborts the previous run. If fn.length >= 1, an AbortSignal is passed (ideal for fetch).

const { data, error, loading, run } = useLatestAsync(
  (signal) =>
    fetch(`/api?q=${encodeURIComponent(filters.search)}`, { signal }).then(
      (r) => r.json(),
    ),
  [filters],
);

run() triggers a manual refetch with the same dependency semantics.


Full example

"use client";

import { useLatestAsync, useUrlState } from "use-param-sync";

export function UsersExplorer() {
  const [filters, setFilters] = useUrlState(
    { search: "", page: 1 },
    { debounce: 300, history: "replace" },
  );

  const { data, loading, error } = useLatestAsync(
    (signal) =>
      fetch(
        `/api/users?search=${encodeURIComponent(filters.search)}&page=${filters.page}`,
        { signal },
      ).then((res) => res.json()),
    [filters],
  );

  return (
    <>
      <input
        value={filters.search}
        onChange={(e) => setFilters({ search: e.target.value })}
      />
      <button
        type="button"
        onClick={() => setFilters({ page: filters.page + 1 })}
      >
        Next page
      </button>
      {loading && <p>Loading…</p>}
      {error && <p>{error.message}</p>}
      {/* render data */}
    </>
  );
}

For a local reference implementation, see examples/demo-users.tsx.


useLatestAsync with Axios

import axios from "axios";

const { data, error, loading } = useLatestAsync(
  (signal) =>
    axios
      .get("/api/users", {
        params: { search: filters.search, page: filters.page },
        signal,
      })
      .then((res) => res.data),
  [filters],
);

Axios (v1+) supports AbortSignal, so previous requests are canceled automatically when dependencies change.

Next.js (App Router)

Use hooks in Client Components ("use client"). The library avoids touching window during SSR; hydration follows the usual pattern (initial render matches the server, then the client reads the URL).


API

useUrlState(initialState, options?)

| | | | ---------------------- | --------------------------------------------------------------------------------------------------- | | Returns | [state, setState]setState accepts a partial object or an updater (prev) => partial \| next | | options.debounce | number (ms). Debounces history writes only. | | options.history | "replace" (default) or "push" |

Merges with the current query string so multiple instances can own different keys on the same page.

useLatestAsync(fn, deps)

| | | | ----------- | ----------------------------------------------------------------------------- | | fn | () => Promise<T> or (signal: AbortSignal) => Promise<T> | | deps | Same idea as useEffect — when they change, the previous request is aborted. | | Returns | { data, error, loading, run } |


Exports

export { useUrlState, useLatestAsync };
export type { UseUrlStateOptions, UseLatestAsyncResult };

Links

  • 🌐 Website: https://use-sync-param.vercel.app/
  • 🎬 Interactive Demo: https://use-sync-param.vercel.app//demo
  • 📦 npm: https://www.npmjs.com/package/use-param-sync
  • 💻 GitHub: https://github.com/i-mml/use-param-sync