MCPcopy Create free account
hub / github.com/react-component/select / useLock

Function useLock

src/hooks/useLock.ts:9–33  ·  view source on GitHub ↗
(duration: number = 250)

Source from the content-addressed store, hash-verified

7 * And after time duration, it will back to `null` automatically.
8 */
9export default function useLock(duration: number = 250): [() => boolean, (lock: boolean) => void] {
10 const lockRef = React.useRef<boolean>(null);
11 const timeoutRef = React.useRef<number>(null);
12
13 // Clean up
14 React.useEffect(
15 () => () => {
16 window.clearTimeout(timeoutRef.current);
17 },
18 [],
19 );
20
21 function doLock(locked: boolean) {
22 if (locked || lockRef.current === null) {
23 lockRef.current = locked;
24 }
25
26 window.clearTimeout(timeoutRef.current);
27 timeoutRef.current = window.setTimeout(() => {
28 lockRef.current = null;
29 }, duration);
30 }
31
32 return [() => lockRef.current, doLock];
33}

Callers 3

SelectorFunction · 0.85
index.tsxFile · 0.85
ComponentFunction · 0.85

Calls

no outgoing calls

Tested by 1

ComponentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…