@queso/debounce

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

Usage no npm install needed!

<script type="module">
  import quesoDebounce from 'https://cdn.skypack.dev/@queso/debounce';
</script>

README

@queso/debounce

npm license Travis Build Status codecov Try @queso/debounce on RunKit

Part of a library of zero-dependency npm modules that do just one thing.

npm

min + gzip | 199 bytes

source

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

Usage

import debounce from '@queso/debounce'

function calculateLayout() {}
const [debounced, cancel] = debounce(calculateLayout, 100)
window.addEventListener('resize', debounced)
cancel()

Parameters

Name Type Description
func TFunc The function to debounce.
wait number The number of milliseconds to which invocations are debounced.
{ leading, trailing } DebounceOptions Specify invoking on the leading or trailing edge of the timeout (Default is trailing=true).

Type parameters

Name Constraint
TFunc (...args: any[]) => any

Returns

A new debounced function paired with a cancel function.

Return type

[(...args: Parameters<TFunc>) => any, () => void]