<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [debounceFunction](./x-components.debouncefunction.md)

## debounceFunction() function

Util function that returns a debounced version of the function passed as parameter. It can use the leading strategy, trailing strategy or both. Using both would result in one leading execution guaranteed and trailing executions only if there are further calls during the length of the debounce time.

**Signature:**

```typescript
debounce: <Params extends any[]>(fn: (...args: Params) => void, debounceTimeInMs: number, input?: DebounceOptions) => DebouncedFunction<Params>
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

fn


</td><td>

(...args: Params) =&gt; void


</td><td>

Function to be debounced.


</td></tr>
<tr><td>

debounceTimeInMs


</td><td>

number


</td><td>


</td></tr>
<tr><td>

{ leading, trailing }


</td><td>

(not declared)


</td><td>

_(Optional)_


</td></tr>
<tr><td>

input


</td><td>

[DebounceOptions](./x-components.debounceoptions.md)


</td><td>

_(Optional)_


</td></tr>
</tbody></table>

**Returns:**

[DebouncedFunction](./x-components.debouncedfunction.md)<!-- -->&lt;Params&gt;

A new function with the debounce.

## Example

Debounce options:

Given this code, where you configure the `trailing` and `leading` options:

```js
const log = debounce(name => console.log(name), 1000, {
  leading
  trailing
});

 log('a'); // +0ms
 log('b'); // +0ms
 log('c'); // +0ms
 setTimeout(() => log('d'), 1000); // +1000ms
 setTimeout(() => log('e'), 1500); // +500ms
 setTimeout(() => log('f'), 2600); // +1100ms
```
\| &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<!-- -->\\ trailing<br/> leading \\ \| \*\*`false`<!-- -->\*\* \| \*\*`true`<!-- -->\*\* \| \|:\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\--\|\-\-\-\-\-\-\-\-\-\-\-\--\|\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\| \| \*\*`false`<!-- -->\*\* \| \| c, e, f \| \| \*\*`true`<!-- -->\*\* \| a, d, f \| a, c, d, e, f \|

