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

ilias-use-debounce

v1.0.0

Published

A lightweight React hook for debouncing function calls with cancellation support and state tracking.

Downloads

97

Readme

⏱️ ilias-use-debounce

A lightweight and type-safe React hook for debouncing function calls with built-in cancellation support and debouncing state tracking.

📦 Installation

npm install ilias-use-debounce
# or
yarn add ilias-use-debounce

🚀 Usage

Import and use the hook directly in your React components:

import { useDebounce } from "ilias-use-debounce";

function SearchComponent() {
  const [searchTerm, setSearchTerm] = useState("");

  const performSearch = (query: string) => {
    console.log("Searching for:", query);
    // Your search logic here
  };

  const [debouncedSearch, cancelSearch, isDebouncing] = useDebounce(
    performSearch,
    500,
  );

  return (
    <div>
      <input
        value={searchTerm}
        onChange={(e) => {
          setSearchTerm(e.target.value);
          debouncedSearch(e.target.value);
        }}
        placeholder="Search..."
      />
      <button onClick={cancelSearch}>Cancel</button>
      {isDebouncing && <span>Searching...</span>}
    </div>
  );
}

🧩 API Reference

useDebounce<T>(fn: T, delay: number): [(...args: Parameters<T>) => void, () => void, boolean]

Debounces a function call, delaying its execution until after the specified delay has elapsed since the last call.

Parameters

  • fn: The function to debounce. Can be synchronous or asynchronous.
  • delay: The delay in milliseconds. Negative values are treated as 0.

Returns

An array with three elements:

  1. debounce (...args: Parameters<T>) => void - The debounced function to call.
  2. cancel () => void - Function to cancel any pending debounced call.
  3. debouncing boolean - State indicating if there's a pending debounced call.

💡 Use Cases

  • Search inputs: Delay API calls until the user stops typing
  • Form validation: Validate input after the user finishes editing
  • Auto-save: Save data after the user stops making changes
  • Window resize handlers: Limit expensive recalculations during resize
  • Scroll events: Reduce the frequency of scroll event handlers

✨ Features

  • TypeScript support - Full type safety with inferred parameter types
  • Cancellation - Cancel pending debounced calls on demand
  • State tracking - Know when a debounced call is pending
  • Async support - Works with both sync and async functions
  • Zero dependencies - Only requires React
  • Small bundle size - Minimal footprint
  • Well tested - Comprehensive test coverage with Vitest

🧪 Testing

This library uses Vitest for testing.

npm test

🤝 Contributing

We welcome contributions!


🛡️ License

This project is licensed under the ISC License.


💡 How It Works

The useDebounce hook creates a debounced version of your function that:

  1. Delays execution until delay milliseconds have passed since the last call
  2. Cancels any previous pending execution when called again
  3. Tracks the debouncing state so you can show loading indicators
  4. Preserves the latest arguments passed to the function