Returns a debounced function that delays calling the input function until after wait milliseconds have elapsed since the last time the debounced function was called. It comes with a .cancel() method to cancel any scheduled input function calls.
Name | Type | Description |
---|---|---|
inputFunction | function | Function to debounce. |
options | object | { {number} wait Time in milliseconds to wait until the input function is called, default: 0. {number} maxWait The maximum time the input function is allowed to be delayed before it's invoked. This can be used to limit the number of calls handled in a constant stream. For example, a media player sending updates every few milliseconds but wants to be handled only once a second, default: infinity. {boolean} before Trigger the function on the leading edge of the wait interval. For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time, default: false {boolean} after Trigger the function on the trailing edge of the wait interval, default: true } |
- Since
- 1.0.0
- Source
The debounced function.
- Type:
- function
import { debounce } from "@gravityforms/utils";
function Example() {
// do something on resize
}
window.addEventListener( 'resize', debounce( Example, { wait: 400 } ) );
Requires
- module:mimicFn