Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Created July 26, 2020 00:09
Show Gist options
  • Save JenniferFuBook/0bbda8d9861b4b88a26a6951a48ec813 to your computer and use it in GitHub Desktop.
Save JenniferFuBook/0bbda8d9861b4b88a26a6951a48ec813 to your computer and use it in GitHub Desktop.
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