Created
January 3, 2023 08:15
-
-
Save qkreltms/8fe98453350c2d819ea3c57bd18a9ede to your computer and use it in GitHub Desktop.
throttle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const throttle = (() => { | |
let isWaiting = false; | |
return (callback: () => void, delay = 100) => { | |
if (isWaiting) { | |
return; | |
} | |
isWaiting = true; | |
setTimeout(() => { | |
callback(); | |
isWaiting = false; | |
}, delay); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
import { throttle } from '';
throttle(() => {}, 1000);