@kietpt2003/react-native-core-ui
Version:
React Native Core UI components by KietPT
36 lines • 1.23 kB
TypeScript
export type DebouncedFunction<F extends (...args: any[]) => any> = {
(...args: Parameters<F>): void;
cancel: () => void;
flush: () => void;
};
/**
* - Creates a debounced function that delays invoking the provided function until after
* a specified delay in milliseconds has elapsed since the last time the debounced
* function was invoked.
* - The debounced function comes with `cancel` and `flush` methods to cancel the
* debounced invocation and to immediately invoke the function, respectively.
* @example
* ```jsx
* import { debounce } from '@kietpt2003/react-native-core-ui/utils';
* const onChangeText = debounce(() => {
* console.log('Function executed!');
* }, 1000);
*
* //Flush case
* const debouncedLog = debounce(logMessage, 2000);
*
* debouncedLog("Waiting 2s...");
* setTimeout(() => {
* debouncedLog.flush(); // Immediately execute the function
* }, 1000);
*
* //Cancel case
* debouncedLog("Canceled");
* setTimeout(() => {
* debouncedLog.cancel(); // Don't execute the function
* }, 1000);
* ```
*/
declare const debounce: <F extends (...args: any[]) => any>(func: F, delay: number) => DebouncedFunction<F>;
export default debounce;
//# sourceMappingURL=debounce.d.ts.map