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-update-next-params

v1.0.3

Published

Custom hook to update URL search params in Next.js App Router

Readme

use-update-next-params

A lightweight custom React hook for updating URL search parameters in Next.js App Router applications.

This hook provides a simple way to add, update, or remove query parameters while preserving existing ones.


📦 Installation

npm install use-update-next-params

or

yarn add use-update-next-params

or

pnpm add use-update-next-params

⚠️ Requirements

  • Next.js 13+ (App Router only)
  • React 18+
  • Must be used inside a Client Component

❗ This hook does not work with the Pages Router (next/router).


🚀 Usage

Basic usage

"use client";

import useUpdateParams from "use-update-next-params";

export default function Page() {
  const updateParams = useUpdateParams();

  return (
    <button onClick={() => updateParams("page", "2")}>
      Go to page 2
    </button>
  );
}

Update a query parameter

updateParams("sort", "asc");

Result:

?sort=asc

Remove a query parameter

updateParams("filter", null);

Result:

?sort=asc

Update one param and remove another

updateParams("page", "3", "filter");

Result:

?page=3

🧠 API

useUpdateParams()

Returns a function that updates URL search parameters.

Function signature

(key: string, value?: string | null, removeKey?: string) => void

Parameters

| Parameter | Type | Description | |------------|---------------------|-------------| | key | string | Query parameter key to set or remove | | value | string \| null | Value to set. If null or undefined, the key is removed | | removeKey | string (optional) | Additional query key to remove |


🔍 How it works

Internally, the hook uses:

  • useRouter
  • usePathname
  • useSearchParams

from next/navigation to construct a new query string and navigate using router.push().


❗ Important Notes

  • Must be used in a Client Component
  • Uses router.push() (not replace)
  • Preserves existing query parameters
  • Designed for Next.js App Router only

🧩 Peer Dependencies

{
  "react": ">=18",
  "next": ">=13"
}

📄 License

MIT © Shibu Dhara