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

@naba-zehra/react-debounce-hook

v1.2.0

Published

A tiny React hook to debounce values

Readme

@naba-zehra/react-debounce-hook

A tiny and simple React hook to debounce values. Perfect for search inputs, filters, and expensive operations.

✨ Features

  • ⚡ Minimal and lightweight (~0.3 kB gzipped)
  • 🎯 Easy to use with any value type
  • 🚀 Zero dependencies
  • 📱 Works with React 17+
  • ✅ TypeScript support

📦 Installation

npm install @naba-zehra/react-debounce-hook

or with yarn:

yarn add @naba-zehra/react-debounce-hook

🚀 Quick Start

import { useState, useEffect } from "react";
import { useDebounce } from "@naba-zehra/react-debounce-hook";

export function SearchComponent() {
  const [searchTerm, setSearchTerm] = useState("");
  const debouncedSearchTerm = useDebounce(searchTerm, 500);

  useEffect(() => {
    if (!debouncedSearchTerm) return;
    
    // Perform API call or expensive operation here
    console.log("Searching for:", debouncedSearchTerm);
    // fetchResults(debouncedSearchTerm);
  }, [debouncedSearchTerm]);

  return (
    <input
      type="text"
      value={searchTerm}
      onChange={(e) => setSearchTerm(e.target.value)}
      placeholder="Search products..."
    />
  );
}

📖 API Reference

useDebounce(value, delay?)

A hook that debounces any value with optional delay.

Parameters:

| Parameter | Type | Default | Description | | --------- | -------- | ------- | ------------------------ | | value | any | - | The value to debounce | | delay | number | 300 | Delay in milliseconds |

Returns: The debounced value

Example:

const debouncedValue = useDebounce(value, 500);

💡 Common Use Cases

1. Search Input

const [query, setQuery] = useState("");
const debouncedQuery = useDebounce(query, 500);

useEffect(() => {
  if (debouncedQuery) {
    searchAPI(debouncedQuery);
  }
}, [debouncedQuery]);

2. Live Filtering

const [filter, setFilter] = useState("");
const debouncedFilter = useDebounce(filter, 300);

const filtered = items.filter(item => 
  item.name.includes(debouncedFilter)
);

3. Auto-save Form

const [formData, setFormData] = useState({});
const debouncedData = useDebounce(formData, 1000);

useEffect(() => {
  if (Object.keys(debouncedData).length > 0) {
    saveToDatabase(debouncedData);
  }
}, [debouncedData]);

⚙️ How It Works

The hook delays updating the returned value until the input stops changing for the specified delay.

Example Timeline:

Without debounce - User types "hello":

User types:  h  e  l  l  o
API calls:   1  2  3  4  5   (5 calls ❌)

With debounce (500ms delay):

User types:  h--e--l--l--o
API calls:   1 (after 500ms)  (1 call ✅)

📌 Best Practices

DO:

  • Use for expensive operations (API calls, complex filtering)
  • Use with useEffect for side effects
  • Combine with loading states for better UX

DON'T:

  • Use the debounced value as form input value (use the original state)
  • Forget to add debounced value to dependency arrays
  • Use very small delays (< 100ms) as it defeats the purpose

🤝 Contributing

Found a bug or want to suggest a feature? Open an issue


📄 License

MIT