Skip to main content

Hook useDebounce

info

Hook allows you to debounce any fast changing value. The debounced value will only reflect the latest value when the useDebounce hook has not been called for the specified time period.

Arguments

ArgumentsTypeMeaningPossible values
valuestring / numberValue for debounceany of type
delaynumberDelay to apply changes if no new valuesfrom 0 to any number



Return

ElementTypeMeaning
debouncedValueanyNew value



Example

const App = () => {
const [searchTerm, setSearchTerm] = useState('')
const debouncedSearchTerm = useDebounce(searchTerm, 500)

return (
<input
placeholder="Search Marvel Comics"
onChange={event => setSearchTerm(event.target.value)}
/>
)
}