1.0.3 • Published 3 years ago

@andideve/react-hooks-usedebounce v1.0.3

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

react-hooks-usedebounce

React hook for callback debouncing

Installation

npm i @andideve/react-hooks-usedebounce

Usage

import { useDebounce } from '@andideve/react-hooks-usedebounce';

function App() {
  const [searchQuery, setSearchQuery] = useState('');
  const [results, setResults] = useState([]);

  useDebounce(
    // function
    () => setResults([]),
    [
      1000, // delay in ms
      [keyword], // watched values
    ],
    // options here
  );

  const handleQueryChange = (event) => {
    setSearchQuery(event.target.value);
  };

  return <main>{/* Some contents */}</main>;
}

Options

options.preventInitialRender

Type: Boolean

Default: true

Skip to function call on first render.

MIT License