1.0.4 • Published 3 months ago

fn-debounce v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Debounce Function

A lightweight module module to help you execute a function after a certain wait time, since the last time it was called. Avoids executing the function too many times when the user interacts continuously (e.g., scrolling, typing)

Usage

import debounce from 'fn-debounce';

const myFunction = () => {
  // ...
};

const debouncedFunction = debounce(myFunction, 1000);

// Call debouncedFunction multiple times
debouncedFunction();
debouncedFunction();
debouncedFunction();

// After 1000ms, myFunction will only be executed once

Parameters

  • func: The function to debounce
  • wait: The wait time in milliseconds
  • immediate: (Optional) If true, the function will be executed immediately, then wait wait ms before executing the next time. Default is false.

Usage examples

  • Debounce the click event of a button to avoid submitting a form repeatedly
  • Debounce the scroll event to only update content when the user stops scrolling
  • Debounce the keyup event to only perform a search after the user has finished typing a string

Contributing

You can contribute to this package by submitting a pull request on GitHub.

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago