debounce

Create a debounced function that delays invoking the callback until the wait time elapses since the last call, ideal for input and resize handlers.

Usage

debounce wraps a function so that it is only invoked after the specified wait time has elapsed since the last call.

import { debounce } from '@movk/core'

const debouncedSearch = debounce((query: string) => {
  console.log('Search:', query)
}, 300)

// Rapid calls — only the last one executes
debouncedSearch('a')
debouncedSearch('ab')
debouncedSearch('abc') // Only this call runs, after 300ms

API

debounce<T>(func, wait)

Create a debounced function that delays invocation until the wait time elapses since the last call.

Parameters

func
T extends (...args: any[]) => any required
The function to debounce.
wait
number required
The debounce delay in milliseconds.

Returns

returns
(...args: Parameters<T>) => void
The debounced function.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License