MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / useThrottle

Function useThrottle

apps/start/src/hooks/use-throttle.ts:4–15  ·  view source on GitHub ↗
(cb: () => void, delay: number)

Source from the content-addressed store, hash-verified

2import { useCallback, useEffect, useRef } from 'react';
3
4export function useThrottle(cb: () => void, delay: number) {
5 const options = { leading: true, trailing: false }; // add custom lodash options
6 const cbRef = useRef(cb);
7 // use mutable ref to make useCallback/throttle not depend on `cb` dep
8 useEffect(() => {
9 cbRef.current = cb;
10 });
11 return useCallback(
12 throttle(() => cbRef.current(), delay, options),
13 [delay],
14 );
15}

Callers 1

WidgetButtonsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected