New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@builtwithjavascript/debounce

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@builtwithjavascript/debounce

Debounce function hook useDebounce.

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

@builtwithjavascript/debounce

Debounce function hook.

Usage

import { useDebounce } from '@builtwithjavascript/debounce'

const debouncedFn = useDebounce(() => {
  // do something
}, 350)

window.addEventListener('resize', debouncedFn)

With function type signature (TypeScript), when debugged function takes parameters:

import { useDebounce } from '@builtwithjavascript/debounce'

const yourFunc = (yourFuncParams: TYourFuncParams) => {
  // ... do something
}
type TYourFunc = typeof yourFunc; // infer yourFunc type

const debouncedFn = useDebounce<TYourFunc>(yourFunc, 350)

const yourFuncParams = {}
debouncedFn(yourFuncParams)

You can also pass a 3rd parameter to this, with a maximum wait time, similar to lodash debounce:

import { useDebounce } from '@builtwithjavascript/debounce'

// If no invokation after 5000ms due to repeated input,
// the function will be called anyway.
const debouncedFn = useDebounce(() => {
  // do something
}, 350, { maxWait: 5000 })

window.addEventListener('resize', debouncedFn)

Optionally, you can get the return value of the function using promise operations:

import { useDebounce } from '@builtwithjavascript/debounce'

const debouncedRequest = useDebounce(() => 'response', 1000)

debouncedRequest().then((value) => {
  console.log(value) // 'response'
})

// or use async/await
async function doRequest() {
  const value = await debouncedRequest()
  console.log(value) // 'response'
}

Credits

Code is from @vueuse npm package and used accordingly to the MIT license: https://vueuse.org/shared/useDebounceFn/

Version:

  • 1.0.5 Added .cancel() and .flush() support

Keywords

debounce, utils, helpers, javascript

FAQs

Package last updated on 25 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts