GuobaGuoba Utils

useThrottle

@guoba-ai/hook / useThrottle

Function: useThrottle()

function useThrottle<T>(value, interval?): T;

Defined in: useThrottle.ts:24

Throttle a value. The returned value updates at most once per interval.

Parameters

value

T

The value to throttle

interval?

number = 500

Minimum time between updates in milliseconds (defaults to 500)

Returns

T

The throttled value

Example

const [position, setPosition] = useState({ x: 0, y: 0 })
const throttledPosition = useThrottle(position, 100)
// throttledPosition updates at most once every 100ms

const throttledValue = useThrottle(value)
// Uses the default 500ms interval

const throttledQuery = useThrottle(query, 300)
// First render returns query immediately; later rapid changes are delayed

Warning

The initial value is returned immediately. Rapid changes publish the latest value after the remaining interval, and pending timers are cleared on unmount.

On this page