useDebounce
A hook to debounce value changes. This can be used to perform an expensive operation based on react state, props or any calculated value.
import {useDebounce} from 'react-use-custom-hooks';
Usage example​
const [query, setQuery] = useState('');
const debouncedQuery = useDebounce(query, delayInMilliseconds);
Playground​
The debouncedQuery value will be updated after delayInMilliseconds after the last change and it can be used to perform a search operation instead of querying the api every time the user types a character.
Live Editor
Result
Loading...
API​
function useDebounce<T>(value: T, delay?: number = 500);
Params​
| Property | Description | Type | Default |
|---|---|---|---|
| value | The value to be debounced. | any | - |
| delay | Delay in milliseconds | number | 500 |