Last active
June 3, 2020 19:41
-
-
Save brombal/1e31a5cf51205e63fd9ef6b8170c3596 to your computer and use it in GitHub Desktop.
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
import { useEffect } from 'react'; | |
/** | |
* Just like useEffect, but only executes after `wait` milliseconds have elapsed since | |
* the last time the dependencies changed. | |
*/ | |
export default function useEffectDebounced(action: () => void, deps: any[], wait: number) { | |
useEffect(() => { | |
const t = setTimeout(action, wait); | |
return () => { | |
clearTimeout(t); | |
}; | |
}, deps); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment