Last active
March 31, 2021 01:17
-
-
Save guamacherox/c699a1fb297a516fe9e33f9abcd4a273 to your computer and use it in GitHub Desktop.
React hook for handling debounce using lodash debounce
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 { useRef } from 'react'; | |
import debounce from 'lodash/debounce'; | |
import PropTypes from 'prop-types'; | |
function useDebounce(customFunction, t = 500) { | |
const debouncedFunction = useRef(debounce(customFunction, t)).current; | |
return debouncedFunction; | |
} | |
useDebounce.propTypes = { | |
customFunction: PropTypes.func.isRequired, | |
t: PropTypes.number | |
}; | |
export default useDebounce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment