Skip to content

Instantly share code, notes, and snippets.

@whoamindx
Created February 2, 2021 20:08
Show Gist options
  • Save whoamindx/ffec0cefa957f688af2390c540e19903 to your computer and use it in GitHub Desktop.
Save whoamindx/ffec0cefa957f688af2390c540e19903 to your computer and use it in GitHub Desktop.
Debounce in few lines
let timer = null;
export const debounce = (func, wait) => () => {
clearTimeout(timer);
timer = setTimeout(func, wait);
};
@whoamindx
Copy link
Author

By context:

export const UtilDebounce = (func, wait) => {
  let timer = null

  return () => {
    clearTimeout(timer)
    timer = setTimeout(func, wait)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment