use-debouncy
🌀 Small (~0.2kb) debounce effect hook for React with TypeScript support
Last updated 5 months ago by eavam .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install use-debouncy 
SYNC missed versions from official npm registry.

useDebouncy

???? Small (~0.2kb) debounce effect hook for React with TypeScript support

GitHub npm bundle size npm types codecov FOSSA Status

Features

  • ???? No dependencies.
  • ????️‍ Tiny. ~0.2kb.
  • ???? Performance. Used by requestAnimationFrame.
  • ???? Types. Support TypeScript.
  • ???? Easy. Use like React effect or function.

Installation

NPM

npm install use-debouncy

Yarn

yarn add use-debouncy

Usage

Demo codesandbox

Use as effect hook

import React, { useState } from 'react';
import { useDebouncyEffect } from 'use-debouncy';

const App = () => {
  const [value, setValue] = useState('');

  useDebouncyEffect(
    () => fetchData(value), // function debounce
    400, // number of milliseconds to delay
    [value], // array values that the debounce depends (like as useEffect)
  );

  return <input value={value} onChange={(event) => setValue(event.target.value)} />;
};

Use as callback function

import React, { useState } from 'react';
import { useDebouncyFn } from 'use-debouncy';

const App = () => {
  const handleChange = useDebouncyFn(
    (event) => fetchData(event.target.value), // function debounce
    400, // number of milliseconds to delay
  );

  return <input value={value} onChange={handleChange} />;
};

API Reference

useDebouncy/effect

function useDebouncyEffect(fn: () => void, wait?: number, deps?: any[]): void;
Prop Required Default Description
fn Debounce callback.
wait 0 Number of milliseconds to delay.
deps [] Array values that the debounce depends (like as useEffect).

useDebouncy/fn

function useDebouncyFn(fn: (...args: any[]) => void, wait?: number): (...args: any[]) => void;
Prop Required Default Description
fn Debounce handler.
wait 0 Number of milliseconds to delay.

Development & Testing

This project uses modern testing approach with Playwright component tests:

Commands

# Run all tests (Playwright component tests)
yarn test

# Run tests with UI mode for debugging
yarn test --ui

# Run linting
yarn lint

# Build the project
yarn build

Test Coverage

The project has comprehensive test coverage including:

  • Core functionality tests - Basic debouncing behavior
  • Effect hook tests - useDebouncyEffect scenarios
  • Function hook tests - useDebouncyFn scenarios
  • Integration tests - Real-world usage patterns
  • Performance tests - Edge cases and performance validation
  • E2E tests - Full application integration with API calls

All tests run across multiple browsers (Chromium, Firefox, WebKit) to ensure cross-browser compatibility.

License

FOSSA Status

Current Tags

  • 5.0.1-beta.3                                ...           beta (3 years ago)
  • 5.1.7                                ...           latest (5 months ago)

56 Versions

  • 5.1.7                                ...           5 months ago
  • 5.1.6                                ...           10 months ago
  • 5.1.5                                ...           10 months ago
  • 5.1.4                                ...           a year ago
  • 5.1.3                                ...           a year ago
  • 5.1.1                                ...           a year ago
  • 5.1.0                                ...           a year ago
  • 5.0.1                                ...           3 years ago
  • 5.0.1-beta.3                                ...           3 years ago
  • 5.0.1-0                                ...           3 years ago
  • 5.0.1-beta.1                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 4.6.0                                ...           3 years ago
  • 4.5.0                                ...           3 years ago
  • 4.4.1                                ...           3 years ago
  • 4.4.0                                ...           3 years ago
  • 4.3.1                                ...           3 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.1                                ...           4 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.1                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.2                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.7                                ...           6 years ago
  • 2.1.6                                ...           6 years ago
  • 2.1.5                                ...           6 years ago
  • 2.1.4                                ...           6 years ago
  • 2.1.3                                ...           6 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.2                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.9.3                                ...           6 years ago
  • 1.9.2                                ...           6 years ago
  • 1.9.1                                ...           6 years ago
  • 1.9.0                                ...           6 years ago
  • 1.8.0                                ...           6 years ago
  • 1.7.0                                ...           6 years ago
  • 1.6.1                                ...           6 years ago
  • 1.6.0                                ...           6 years ago
  • 1.5.0                                ...           6 years ago
  • 1.4.0                                ...           6 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |