Detalhes do pacote

use-debouncy

eavam153.6kMIT5.1.6

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

debounce, use-debounce, react debounce, debounce hook

readme (leia-me)

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

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

5.1.5 (2025-06-01)

5.1.4 (2025-05-25)

Bug Fixes

  • remove hardcoded npm token from .yarnrc.yml (#1188) (d44be71)

5.1.3 (2025-05-24)

Bug Fixes

  • after switching to tsup, the configuration was updated, which reduced the size of the final build (#1185) (7ea2cd6)
  • improve release workflow and npm authentication (#1187) (a32d8e3)
  • update authentication steps and configuration for npm and yarn (#1186) (e54dbc4)

5.1.0 (2025-05-23)

Bug Fixes

  • ci: resolve release-it workflow issues in CI environment (#1184) (a882e92)

Features

  • migrate to modern toolchain (Biome, tsup, release-it, Node.js 20) (#1183) (defbab6)

5.0.1 (2023-09-24)

Bug Fixes

5.0.1-beta.3 (2023-09-23)

Bug Fixes

5.0.1-beta.2 (2023-09-23)

Bug Fixes

5.0.1-beta.1 (2023-09-23)

Bug Fixes

5.0.0 (2023-09-19)

Bug Fixes

Features

BREAKING CHANGES

  • Includes were removed by default as tree-shaking should do its job.

  • fix: remove useless files in config

4.6.0 (2023-09-19)

Features

4.6.0 (2023-09-19)

Features

4.5.0 (2023-09-19)

Bug Fixes

Features

Changelog

4.7.0 (2023-08-28)

Bug Fixes

Features

4.4.0 (2022-12-11)

Features

4.3.1 (2022-12-09)

Bug Fixes

4.3.0 (2022-03-26)

Features

4.2.1 (2021-10-24)

Bug Fixes

4.2.0 (2021-05-23)

Bug Fixes

Features

  • optimize size (7b3bb0c)
  • removed fragile code related to fps timing (2355c07)

4.1.1 (2021-04-19)

Reverts

  • Revert "feat: removed fragile code related to fps timing" (1f5f684)
  • Revert "feat: optimize size" (cf3aad7)
  • this reverts commit 5952cffe6d1333c14836e2e033681af703bdfc86 (3f9f784)
  • this reverts commit e2f60d284e534e53eb6082ff62a6096cc3462e01 (cf6b851)

4.1.0 (2021-04-18)

Features

  • optimize size (e2f60d2)
  • removed fragile code related to fps timing (5952cff)

4.0.2 (2021-04-17)

Bug Fixes

  • changed postinstall to prepare (d5ec166), closes #477

4.0.1 (2021-03-14)

Bug Fixes

4.0.0 (2021-03-14)

Features

  • add useDebouncy as function (42e436f)

BREAKING CHANGES

  • Now hooks need to be imported from fn or effect subdirectory

3.1.1 (2021-03-12)

Bug Fixes

  • parcel version > 1.12.3 is broken (f651d32)

3.1.0 (2020-11-29)

Bug Fixes

Features

3.0.1 (2020-09-14)

Bug Fixes

  • change flag for bit release (2ccd423)

3.0.0 (2020-09-14)

Features

  • settimeout replaced on rAF (5af7ab9)

BREAKING CHANGES

  • Instead of setTimeout is used now requestAnimationFrame.

2.2.0 (2020-08-16)

Features

2.1.7 (2020-07-09)

Bug Fixes

  • optimize e2e test and add more matrix in CI (#63) (8939446)

2.1.6 (2020-07-05)

Bug Fixes

  • add import compiler for bit (531f3cb)
  • add import compiler for bit (0b2ca84)
  • add import compiler for bit (396e901)

2.1.5 (2020-07-05)

Bug Fixes

2.1.4 (2020-07-05)

Bug Fixes

  • add description for install in bit and try release workflow (0cc9dd7)

2.1.3 (2020-07-05)

Bug Fixes

2.1.2 (2020-07-05)

Bug Fixes

  • add pull latest bit object (41538e0)

2.1.1 (2020-07-05)

Bug Fixes

  • disabled reporting for bit (0c59ffb)

2.1.0 (2020-07-05)

Features

2.0.2 (2020-07-04)

Bug Fixes

  • change size limit and add info about side effects (8df54bb)

2.0.1 (2020-07-02)

Bug Fixes

  • update information about bundle size (38017d2)

2.0.0 (2020-07-02)

Bug Fixes

  • add e2e tests in release workflow (23928e3)
  • add newline at end gitignore (c66ba7f)

Features

  • add e2e tests (34cc610)
  • changed hook for minimize useEffect calls (26c608a)

BREAKING CHANGES

  • Change track first mount call. setTimeout reference moved in lexical scope. The call happens clearTimeout with every deps update.

1.9.3 (2020-07-01)

Bug Fixes

1.9.2 (2020-06-28)

Bug Fixes

  • current timer state allocated to a separate variable (9d8846e)

1.9.1 (2020-06-25)

Bug Fixes

1.9.0 (2020-06-24)

Features

1.8.0 (2020-06-24)

Bug Fixes

Features

  • add clear timer on unmount to avoid memory leaks (56f2c4c)

1.7.0 (2020-06-23)

Bug Fixes

Features

  • compress size bundle (0d2976e)
  • remove update function for comprese size (a71b259)

1.6.1 (2020-06-23)

Bug Fixes

  • remove duplicate link in codesandbox (ebe87b6)

1.6.0 (2020-06-23)

Features

1.5.0 (2020-06-23)

Features

1.4.0 (2020-06-23)

Bug Fixes

  • move size-limit workflows (2ea23f5)

Features

1.3.0 (2020-06-23)

Features

  • add disable call debounce on first mount (dd5b41f)

1.2.1 (2020-06-23)

Bug Fixes

1.2.0 (2020-06-23)

Bug Fixes

  • add github token in cmd (9cf7da5)
  • add persist-credentials for correct push semantic-release (c175f74)
  • add semantic-release in deps (97ff8b6)
  • change env name (85a122d)
  • change token on admin token for semantic-release (73efa66)

Features