use-lock-fn
shadcn-hooks/use-lock-fnFreeHook
A hook to lock a function until the previous promise is resolved
Install it
npx shadcn@latest add https://shadcn-hooks.com/r/use-lock-fn.jsonSource
1import { useCallback, useRef } from 'react'23export function useLockFn<P extends any[] = any[], V = any>(4 fn: (...args: P) => Promise<V>,5) {6 const lockRef = useRef(false)78 return useCallback(9 async (...args: P) => {10 if (lockRef.current) {11 return12 }1314 lockRef.current = true1516 try {17 return await fn(...args)18 } finally {19 lockRef.current = false20 }21 },22 [fn],23 )24}
Files it writes
More from shadcn-hooks
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| use-active-elementuse-active-element | shadcn-hooks | Hooks | Free | no deps | |
| use-batteryuse-battery | shadcn-hooks | Hooks | Free | no deps | |
| use-booleanuse-boolean | shadcn-hooks | Hooks | Free | no deps | |
| use-click-any-whereuse-click-any-where | shadcn-hooks | Hooks | Free | no deps | |
| use-click-awayuse-click-away | shadcn-hooks | Hooks | Free | no deps | |
| use-clipboarduse-clipboard | shadcn-hooks | Hooks | Free | no deps | |
| use-controllable-valueuse-controllable-value | shadcn-hooks | Hooks | Free | 1 dep | |
| use-counteruse-counter | shadcn-hooks | Hooks | Free | no deps |
