useThrottle
Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.
Demo
Delay is set to 1000ms for this demo.
Button clicked: 0
Event handler called: 0
Usage
js
import { useThrottle } from 'comuse-core'
const throttledFn = useThrottle(() => {
// do something, it will be called at most 1 time per second
}, 1000)
window.addEventListener('resize', throttled)