0.0.1 • Published 3 years ago

@ofqwx/use-debounce-callback v0.0.1

Weekly downloads
-
License
UNLICENCED
Repository
github
Last release
3 years ago

useDebounceCallback

Simple hook to debounce a callback function for a specific amount of time.

Installation

yarn add @ofqwx/use-debounce-callback

Example

import useDebounceCallback from "@ofqwx/use-debounce-callback";
// or from @ofqwx/react-hooks:
// import { useDebounceCallback } from "@ofqwx/react-hooks

function InputField() {
  const [value, setValue] = useState('');
  
  function onChange(e) {
    setValue(e.target.value);
  }

  // function onChange will be executed only after debouncedOnChange is not called for 400ms
  const debouncedOnChange = useDebounceCallback(onChange, 400);

  return <input onChange={debouncedOnChange} />;
}

Tests

yarn install
yarn test