Created
October 25, 2021 13:02
-
-
Save sameroso/085f5f2cdbdf6da226038d02992e3dde 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 { useMemo } from "react"; | |
import { debounce } from "lodash"; | |
export function useDebounceCallback(callback: (...values: any[]) => void, delay: number) { | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
const onChangeDebounce = useMemo(() => debounce(callback, delay), []); | |
useEffect(() => { | |
return () => onChangeDebounce.cancel(); | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, []); | |
return onChangeDebounce; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment