Skip to main content

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

PropertyDescriptionTypeDefault
valueThe value to be debounced.any-
delayDelay in millisecondsnumber500