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

@lonestone/usedebounce

v1.0.3

Published

React hooks for debouncing value or function calls

Readme

React Debounce Hooks

A collection of React hooks for debouncing values and functions to optimize performance and limit the rate of executions.

Installation

npm install @lonestone/usedebounce
# or
yarn add @lonestone/usedebounce
# or
pnpm add @lonestone/usedebounce

Features

  • 🎯 Debounce values or functions
  • ⚡️ Optimized performance
  • 🔄 Automatic cleanup
  • ⏱️ Configurable delay
  • 💪 TypeScript support
  • 🧪 Well tested

Usage

useDebounceValue

Use this hook when you want to debounce a value that changes frequently (e.g., search input, form fields).

import { useDebounceValue } from '@lonestone/usedebounce'

function SearchComponent() {
  const [searchTerm, setSearchTerm] = useState('')
  const debouncedSearchTerm = useDebounceValue(searchTerm, 500)

  useEffect(() => {
    // This effect will only run 500ms after the last searchTerm change
    console.log('Searching for:', debouncedSearchTerm)
  }, [debouncedSearchTerm])

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

useDebounceFunction

Use this hook when you want to debounce a function that gets called frequently (e.g., event handlers, API calls).

import { useDebounceFunction } from '@lonestone/usedebounce'

function AutosaveForm() {
  const save = async (data: FormData) => {
    await api.save(data)
  }

  // Create a debounced version of the save function
  const debouncedSave = useDebounceFunction(save, 1000)

  return (
    <form
      onChange={(e) => {
        const data = new FormData(e.currentTarget)
        // This will only call save() once, 1000ms after the last change
        debouncedSave(data)
      }}
    >
      {/* form fields */}
    </form>
  )
}

API Reference

useDebounceValue

function useDebounceValue<T>(value: T, delay: number): T

Parameters

| Parameter | Type | Description | | --------- | -------- | ------------------------- | | value | T | The value to debounce | | delay | number | The delay in milliseconds |

Returns

Returns the debounced value of type T.

useDebounceFunction

function useDebounceFunction<T extends (...args: any[]) => any>(
  fn: T,
  delay: number
): (...args: Parameters<T>) => void

Parameters

| Parameter | Type | Description | | --------- | -------- | ------------------------- | | fn | T | The function to debounce | | delay | number | The delay in milliseconds |

Returns

Returns a debounced version of the provided function that:

  • Has the same parameters as the original function
  • Returns void (since it's debounced)
  • Will only execute after the specified delay
  • Will cancel any pending executions when called again

Backward Compatibility

For backward compatibility, the default export is an alias for useDebounceValue:

import { useDebounce } from '@lonestone/usedebounce'
// useDebounce is the same as useDebounceValue

Best Practices

When to use useDebounceValue

  • Form inputs that trigger expensive operations
  • Search inputs that make API calls
  • Window resize or scroll event values
  • Any frequently changing value that triggers side effects

When to use useDebounceFunction

  • Event handlers that make API calls
  • Save functions for auto-saving forms
  • Window resize or scroll event handlers
  • Any callback that gets called frequently and needs rate limiting

License

This project is licensed under the Unlicense.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.