@ofqwx/use-debounce-callback

0.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @ofqwx/use-debounce-callback

Weekly Downloads

2

Version

0.0.1

License

UNLICENCED

Unpacked Size

2.5 kB

Total Files

6

Last publish

Collaborators

  • ofqwx