I wrote this hook (there could be bugs, I haven't used it yet):
import { useCallback, useEffect } from 'react';
import _throttle from 'lodash/throttle';
export function useThrottledCallback(cb, delay, ...deps) {
const callback = useCallback(_throttle(cb, delay), deps);
useEffect(() => {
const lastCallback = callback;
return () => lastCallback.cancel();
}, [callback]);
return callback;
}
Is there a way I can make the exhaustive-deps rule lint usages of this hook?
useThrottledCallback(() => (a + b + c)}, 100, [])
In this usage, I'd like to be notified that a
, b
, and c
need to be in the dependency array.