A simple debounce package made for any javascript project.
No dependencies.
npm i any-debounceYou can use the debouncer function to debounce a function and the useDebounce function to debounce a value.
Debouncing a value
Great for input fields using react and useState.
import { useDebounce } from "any-debounce";
import { useState } from "react";
const [value, setValue] = useState("");
const debouncedValue = useDebounce(value, 1000);Debouncing a function
Great for when you don't want to use useState.
import { debouncer } from "any-debounce";
const handleOnChange = debouncer((value) => {
console.log(value);
//do something with the value
}, 1000);used any-debounce 0.0.2? see breaking changes below.
useDebounceis nowdebounceValuefor debouncing a valuedebounceris the newdebouncefor debouncing a function