Skip to content

Instantly share code, notes, and snippets.

@christianvmm
Last active March 4, 2024 04:48
Show Gist options
  • Select an option

  • Save christianvmm/dba7ad4db2108d149aa44d9c89cf8704 to your computer and use it in GitHub Desktop.

Select an option

Save christianvmm/dba7ad4db2108d149aa44d9c89cf8704 to your computer and use it in GitHub Desktop.
export const debounce = (func) => {
let timer;
return function(...args) {
const context = this;
if(timer) clearTimeout(timer);
timer = setTimeout(() => {
timer = null;
func.apply(context, args);
}, 500);
}
}
// Ejemplo de uso
const optimizedSearch = useCallback(debounce(searchFunction), []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment