Skip to content

Instantly share code, notes, and snippets.

@chestercharles
Created September 20, 2019 18:34
Show Gist options
  • Select an option

  • Save chestercharles/ed5f67b6b2fecde1854986bd64d4f70c to your computer and use it in GitHub Desktop.

Select an option

Save chestercharles/ed5f67b6b2fecde1854986bd64d4f70c to your computer and use it in GitHub Desktop.
Hook to throttle a callback function
export function useThrottledCallback(cb, ms) {
const [callable, setCallable] = useState(true);
return () => {
if (callable) {
cb();
setCallable(false);
setTimeout(() => setCallable(true), ms);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment