useThrottle

Throttle computationally expensive operations with useThrottle.

Install:

npm i @uidotdev/usehooks

Description:

The useThrottle hook offers a controlled way to manage execution frequency in a React application. By accepting a value and an optional interval, it ensures that the value is updated at most every interval milliseconds. This is particularly helpful for limiting API calls, reducing UI updates, or mitigating performance issues by throttling computationally expensive operations.

Parameters

NameTypeDescription
valueanyThe value to throttle.
intervalnumber(Optional) The interval in milliseconds. Default: 500ms.

Return Value

NameTypeDescription
throttledValueanyThe throttled value that is updated at most once per interval.

Demo:

Example:

More Hooks:

Sort: