Created
July 26, 2020 00:09
-
-
Save JenniferFuBook/0bbda8d9861b4b88a26a6951a48ec813 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 { useCallback, useState } from "react"; | |
import debounce from "lodash/debounce"; | |
export const useDebouncedValue = (initialValue, wait) => { | |
const [debouncedValue, setDebouncedValue] = useState(initialValue); | |
const debouncedFunction = useCallback(debounce(setDebouncedValue, wait), []); | |
return [debouncedValue, debouncedFunction]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment